Open ptrushin opened 6 years ago
I have faced this exact issue. Any way to disable cookies from adding in the request??
Unfortunately I've got the same issue. Has anybody found a solution or workaround?
Hello, I was stuck in this problem too.
The problem went away when I registered the authentication stuff before all OData stuff.
It aint pretty, but I worked around this issue by pulling a fast one on the "UseODataBatching" middleware.
app.Use(async (context, next) => { context.Request.Headers["CookieBackup"] = context.Request.Headers["Cookie"]; context.Request.Headers.Remove("Cookie"); await next(); });
app.UseODataBatching();
app.Use(async (context, next) => { context.Request.Headers["Cookie"] = context.Request.Headers["CookieBackup"]; context.Request.Headers.Remove("CookieBackup"); await next(); });
Hello, I was stuck in this problem too.
The problem went away when I registered the authentication stuff before all OData stuff.
Thanks, mate, it helped me.
Hello, I was stuck in this problem too.
The problem went away when I registered the authentication stuff before all OData stuff.
Can you please elaborate how you did. it is working in local but in server it gives this error. in start up I have below.
Looks like it was fixed as part of this pr #2379
Looks like it was fixed as part of this pr #2379
Yes I am using 8.0.0-beta and this is fixed.
I think it is because in file https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNetCore.OData/Batch/ODataBatchReaderExtensions.cs
in line 227 context.Request.Cookies = originalContext.Request.Cookies; add a "Cookie" key in context.Request.Headers and
in line 230 context.Request.Headers.Add(header); add it again
Assemblies affected
Microsoft.AspNetCore.OData/7.0.1
Reproduce steps
Odata batch request with cookie
Expected result
Ok
Actual result
Exception
Additional detail
System.ArgumentException: An item with the same key has already been added. Key: Cookie at System.Collections.Generic.Dictionary
2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value) at Microsoft.AspNetCore.Http.HeaderDictionary.Add(KeyValuePair2 item) at Microsoft.AspNet.OData.Batch.ODataBatchReaderExtensions.CreateHttpContext(HttpContext originalContext) at Microsoft.AspNet.OData.Batch.ODataBatchReaderExtensions.ReadOperationInternalAsync(ODataBatchReader reader, HttpContext originalContext, Guid batchId, Nullable
1 changeSetId, CancellationToken cancellationToken, Boolean bufferContentStream) at Microsoft.AspNet.OData.Batch.DefaultODataBatchHandler.ParseBatchRequestsAsync(HttpContext context) at Microsoft.AspNet.OData.Batch.DefaultODataBatchHandler.ProcessBatchAsync(HttpContext context, RequestDelegate nextHandler) at Microsoft.AspNet.OData.Batch.ODataBatchMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)