Solutions that cannot contain commas in C # cookies

Source: Internet
Author: User

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:

  • Equal sign (=)

  • Semicolon (;)

  • Comma (,)

  • line break (\ n)

  • return character (\ r)

  • tab (\ t)

  • Space character

  • Dollar sign ($) as the first character

  • Or

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.