C#cookie Merging Updates

Source: Internet
Author: User

Httpcode version

   /// <summary>        ///merge cookies, cookie2 and Cookie1 merge update return string type cookie/// </summary>        /// <param name= "Cookie1" >Old Cookie</param>        /// <param name= "Cookie2" >New Cookie</param>        /// <returns></returns>         Public stringUpdatecookie (stringCookie1,stringcookie2) {StringBuilder SB=NewStringBuilder (); Dictionary<string,string> Diccookie =Newdictionary<string,string>(); //Traverse Cookie1            if(!string. IsNullOrEmpty (Cookie1)) {foreach(stringCookiesinchCookie1. Replace (',',';'). Split (';'))                {                    if(!string. IsNullOrEmpty (cookies) && cookies. IndexOf ('=') >0)                    {                        stringKey = Cookie. Split ('=')[0].                        Trim (); stringValue = Cookie. Substring (key. Length +1).                        Trim (); if(Diccookie.containskey (key)) {Diccookie[key]=cookies; }                        Else{diccookie.add (key, Cookie); }                    }                }            }            if(!string. IsNullOrEmpty (Cookie2)) {//Traverse Cookie2                foreach(stringCookiesinchCookie2. Replace (',',';'). Split (';'))                {                    if(!string. IsNullOrEmpty (cookies) && cookies. IndexOf ('=') >0)                    {                        stringKey = Cookie. Split ('=')[0].                        Trim (); stringValue = Cookie. Substring (key. Length +1).                        Trim (); if(Diccookie.containskey (key)) {Diccookie[key]=cookies; }                        Else{diccookie.add (key, Cookie); }                    }                }            }            inti =0; foreach(varIteminchDiccookie) {i++; if(I <diccookie.count) {sb. Append (item. Value+";"); }                Else{sb. Append (item.                Value); }            }            returnsb.        ToString (); }

Universal Frame Version

        /// <summary>        ///automatically merge the values of two cookies to return the updated results/// </summary>        /// <param name= "Cookie1" >Cookie1</param>        /// <param name= "Cookie2" >Cookie2</param>        /// <returns>returns the updated cookie</returns>        Internal Static stringGetmergecookie (stringCookie1,stringcookie2) {            if(string. Isnullorwhitespace (COOKIE1))//The new one is empty.            {                returnCookie2;//back to the old            }            if(string. Isnullorwhitespace (Cookie2))//The old one is empty.            {                returnCookie1;//returns the new} List<string> cookielist =Newlist<string> ();//Results            string[] list_1 = Cookie1. ToString (). Split (';'); string[] list_2 = Cookie2. ToString (). Split (';'); foreach(stringIteminchlist_1) {                //Exclude Duplicates                if(Cookielist. Contains (item))Continue; //Docking Cookie Basic key and value stringCookielist. ADD (string. Format ("{0}", item)); }            foreach(stringIteminchlist_2) {                //Exclude Duplicates                if(Cookielist. Contains (item))Continue; //Docking Cookie Basic key and value stringCookielist. ADD (string. Format ("{0}", item)); }            return string. Join (";", cookielist); }

C#cookie Merging Updates

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.