Link to home
Create AccountLog in
Avatar of adworldmedia
adworldmediaFlag for United States of America

asked on

Cookie with value separated by commas parsed incorrectly

I am attempting to read a cookie:
{FFcat=607,19330,15}

Open in new window


By using an HttpWebRequest CookieContainer call to a web page.

Each and everytime Asp.net c# V2.X reads this as THREE seperate cookies:
(FFcat=607}
{19330=}
{15=}

Open in new window


How do I correctly read this cookie?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I think they are being written wrong.  ',' is a separator between cookies and a reserved character.  The usual requirement for reserved characters in HTTP URLs, requests, and responses is that reserved characters must be UrlEncoded.

http://stackoverflow.com/questions/1136405/handling-a-comma-inside-a-cookie-value-using-nets-c-system-net-cookie

http://msdn.microsoft.com/en-us/library/aa289495%28v=vs.71%29.aspx

http://en.wikipedia.org/wiki/HTTP_cookie
ASKER CERTIFIED SOLUTION
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of adworldmedia

ASKER

None of those links supports what I need to do.  I relinquished to the fact that Asp.net will not be able to parse incoming cookies with comma delimited values.

So I have decided I will re-build the cookie from scratch, and re-submit it into the header.  But, as I have found out; I can not create or save a new cookie with a value that has commas in it...

I am working with an external web service, and it requires the commas.  I can not URLEncode the value, because when submitted it will not work.  The external server is looking for comma delimited values.  How can I get this to work?

Server Error in '/' Application.
The 'Value'='607,19330,15' part of the cookie is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.CookieException: The 'Value'='607,19330,15' part of the cookie is invalid.

Source Error:


Line 67:                 passCookie.Add(new Uri("http://88.com"), new Cookie(cookieJar[loop1].Name, cookieJar[loop1].Value));
Line 68:             }
Line 69:             passCookie.Add(new Uri("http://88.com"), new Cookie("FFcat",  "607," + _channelID + ",15"));
Line 70:         }
Line 71:         return passCookie;


Source File: c:\Users\Joseph\documents\visual studio 2012\websites\cookies\Default.aspx.cs    Line: 69

Open in new window