title: handling a comma inside a cookie value using .net's (C#) System.Net.Cookie
body: <p>I'm creating a client to visit a website and log in + do some tasks automatically, however they recently updated their cookies to (for whatever reason...) contain a comma inside their identification cookie. </p>
  
  <p>So for example, the Cookie will have a value similar to this:</p>
  
  <pre><code>a,bcdefghijklmnop
  </code></pre>
  
  <p>The problem is, according to <a href="http://msdn.microsoft.com/en-us/library/system.net.cookie.value.aspx" rel="noreferrer">msdn</a> you can't use a comma nor a period inside a cookie's value. What I'm looking for is a way around this limitation, some way to make .net's Cookie's work nice with the commas. I've found that the server does send a 'SET-COOKIE' header to the client and I'm guessing that's what is being parsed, but that also seems to obviously give special meaning to commans and semicolons as well (thus the limitation of the class inside .NET itself). </p>
  
  <p>But then how does a browser such as IE, Firefox, etc... handle the cookie properly (as they clearly do, since the website works fine in any browsers I've tested it with.) Is there maybe a way to force this behaviour in .NET?</p>
  
  <p>Any help would be appreciated, thanks.</p>
  
  <h3>--- EDIT ---</h3>
  
  <p>some additional information:</p>
  
  <p>My code looks something like this:</p>
  
  <pre><code>request = (HttpWebRequest)WebRequest.Create(URI); 
  request.CookieContainer = Program.client.cookieJar;
  </code></pre>
  
  <p>Where cookieJar is defined in Program.client as:</p>
  
  <pre><code>CookieContainer cookieJar = new CookieContainer();
  </code></pre>
  
  <p>When i loop through and print out all the cookies in the CookieContainer, I get something like this: (cookies, in the format: "name" -> "value")</p>
  
  <pre><code>"normal_cookie" -&gt; "i am the value" 
  "messedup_cookie" -&gt; "a" 
  "bcdefghijklmnop" -&gt; "" 
  
  // What I should get is this: 
  "normal_cookie" -&gt; "i am the value" 
  "messedup_cookie" -&gt; "a,bcdefghijklmnop" 
  </code></pre>
  
  <p>The core of the problem seems to be that commas and semi colons are reserved characters in the SET-COOKIE header string...but then how do browsers handle this? I can probably parse the string myself but I don't know how to get around situations such as this one: (HTTP header, in the format: "name" -> "value")</p>
  
  <pre><code>"Set-Cookie" -&gt; "messedup_cookie=a,bcdefghijklmnop; path=/; domain=.domain.com; expires=Sat, 15-Aug-2009 09:14:24 GMT,anothervariable=i am the value;"
  </code></pre>
  
  <p>As you can see, the expires section looks for a comma instead of a semicolon to differentiate itself from the next variable. As far as I can tell, it's in the format:</p>
  
  <pre><code>cookie1_var1=value; cookie1_var2=value,cookie2_var1=value; cookir2_var2=value
  </code></pre>
  
  <p>But if that's true, is there an elegant way to deal with commas that may occur inside one of the values?</p>