This is the description in MSDN:
Exception |
conditions |
Cookieexception |
name is null or an empty string (""). Or the name contains unauthorized characters. using one of the following characters will cause an exception:
value is null, or contains a semicolon (;) or commas (,), which are not enclosed in escaped double quotes. |
the comma character is reserved for use as a delimiter between individual cookies on the same line. The following example shows how to use commas in value .
System.Net.Cookie Cookie = new System.Net.Cookie ("Cookieid", "\" 123,456\ "");
The first method:
</pre><pre name= "code" class= "CSharp" >string cookiestr = WebBrowser1.Document.Cookie; if (!cookiestr.contains ("jsession_id")) { return; } string[] Cookstr = Cookiestr.split (';'); foreach (String str in cookstr) { string[] cookienamevalue = str. Split (' = '); String cookiename = Cookienamevalue[1]. Trim (). ToString (); CookieName = Cookiename.replace (",", "%2c"); Cookie CK = new Cookie (cookienamevalue[0). Trim (). ToString (), cookiename); Ck. Domain = WebBrowser1.Document.Domain; Mycookiecontainer.add (CK); }
The second method:
string cookiestr = WebBrowser1.Document.Cookie; if (!cookiestr.contains ("jsession_id")) { return; } string[] Cookstr = Cookiestr.split (';'); foreach (String str in cookstr) { string[] cookienamevalue = str. Split (' = '); String cookiename = Cookienamevalue[1]. Trim (). ToString (); if (Cookiename.contains (",")) { cookiename = "\" "+ CookieName +" \ "; } Cookie CK = new Cookie (cookienamevalue[0). Trim (). ToString (), cookiename); Ck. Domain = WebBrowser1.Document.Domain; Mycookiecontainer.add (CK); }
Solutions that cannot contain commas in C # cookies