Silverlight OData Services Sending Multiple Cookies
-
lunes, 02 de abril de 2012 8:32
I'm trying to pass multiple cookies to an OData service from a Silverlight application. I'm subclassing a DataServiceContext and wiring up to the SendingRequest event and doing the following:
protected virtual void OnDataSourceSendingRequest(object sender, SendingRequestEventArgs e)
{
CookieContainer cookieContainer = new CookieContainer();
foreach (var cookieContent in _cookies)
{
Cookie cookie = new Cookie(cookieContent.Key, cookieContent.Value.Value);
cookieContainer.Add(new Uri("http://localhost", UriKind.Absolute), cookie);
}
var cookieHeader = cookieContainer.GetCookieHeader(new Uri("http://localhost", UriKind.Absolute));
e.RequestHeaders["Cookie"] = cookieHeader;}
If you look at the headers using Fiddler, only the first Cookie is propagated to the request. Is this a bug or am I doing something wrong?
Todas las respuestas
-
viernes, 13 de abril de 2012 0:08
I repro'd your issue and was able to fix it by getting the cookieHeader string to delimit the cookies with a comma instead of a semicolon, which is what the GetCookieHeader method seems to generate by default.
I don't really know anything about this, but looking at http://msdn.microsoft.com/en-us/library/system.net.cookie.aspx, I think there are multiple specifications for how the header is written. Might have something to do with that. I can investigate more if that would be helpful, but that might be enough to get you rolling again.-Ian
-
viernes, 13 de abril de 2012 7:19
Ian,
Thanks for the reply. Interesting. I'll have a fiddle and see if comma-delimiting works for me.
-
lunes, 16 de abril de 2012 18:37Any luck with the comma-delimiting?
-Ian

