Cannot call set cookies because my cookie list contains commas  
Author Message
MatthewVincent





PostPosted: Visual Studio Team System - Testing, Cannot call set cookies because my cookie list contains commas Top

I'm trying to call set cookies and have done so successfully but have become blocked.

I have a list of names to put into the cookie and it looks like so:

CookieName=A.aspx,B.aspx,C.aspx,D.aspx,E.aspx

I'm calling

Context.CookieContainer.SetCookies(uri, "CookieName=A.aspx,B.aspx,C.aspx,D.aspx,E.aspx; expires=Fri, 31-Dec-9999 23:59:59 GMT; path=/");

the problem is my call gets broken up because of the commas, I tried using %2c instead but later the developer's code expects unencoded commas. So I need to know if there is any way to create a cookie value with commas



Visual Studio Team System36  
 
 
Anutthara - MSFT





PostPosted: Visual Studio Team System - Testing, Cannot call set cookies because my cookie list contains commas Top

Hi MatthewVincent,

If you want to put a comma in the cookie value, you will have to escape the comma, else it is treated as a de-limiter in the .NET fx call SetCookies(). Note that RFC 2109 and 2965 state that multiple cookies can be set in a single Set-Cookie or Set-Cookie2 header, and that the cookies are comma-separated. The comma is _not_ a valid character in a cookie without being escaped.

Hope that helps.

- Anu



 
 
MatthewVincent





PostPosted: Visual Studio Team System - Testing, Cannot call set cookies because my cookie list contains commas Top

What is the escape character for a comma I get an error when i try to use '\' and can't seem to find other options anywhere.
 
 
Anutthara - MSFT





PostPosted: Visual Studio Team System - Testing, Cannot call set cookies because my cookie list contains commas Top

You could simply use the encoded value as you have suggested before. Or use the escape() function in Javascript if you are setting the cookie through script