C # Read and write Cookie general function

Source: Internet
Author: User

#region Read or write cookie        ///         ///Write Cookie value         ///         ///name         ///value          public static void Writecookie (String strName, string strvalue)          {            httpcookie cookie = httpcontext.current.request.cookies[strname];             if (cookie = null)             {                 cookie = new HttpCookie (strName);            }         &Nbsp;   cookie. Value = UrlEncode (strvalue);             HttpContext.Current.Response.AppendCookie (Cookie);        }          ///        ///Write Cookie value         ///        ///name          ///value         public static void Writecookie (String strName, String key, String strvalue)         {             httpcookie cookie = httpcontext.current.request.cookies[strname];             if (cookie = null)             {                  cookie = new HttpCookie (strName);             }             cookie[key] = UrlEncode (strvalue);             httpcontext.current.response.appendcookie (Cookie);         }         ///         ///Write Cookie value         ///         ///name         ///value          public static void Writecookie (string strName, String key, String strvalue, int expires)    & nbsp;    {             HttpCookie COokie = httpcontext.current.request.cookies[strname];             if (Cookie = = null)             {                 cookie = new HttpCookie (StrName);            }             cookie[key] = UrlEncode (strValue);             cookie. Expires = DateTime.Now.AddMinutes (Expires);             httpcontext.current.response.appendcookie (cookie);         }          ///        /// Write Cookie value         ///  &Nbsp;     ///name         ///value          ///Expiration Time (minutes)         public static void Writecookie (String strName, string strvalue, int expires)         {             httpcookie cookie = httpcontext.current.request.cookies[strname];             if (cookie = null)             {                 cookie = new HttpCookie (strName);            }             cookie. Value = UrlEncode (strvalue);           &nbsP; cookie. Expires = DateTime.Now.AddMinutes (Expires);             httpcontext.current.response.appendcookie (cookie);         }          ///        /// Read Cookie value         ///        /// Name         ///Cookie Value          public static string GetCookie (String strName)         {             if (HttpContext.Current.Request.Cookies! = null && Httpcontext.current.request.cookies[strname]! = null)                  return UrlDecode (Httpcontext.current.request.cookies[strname]. Value. ToString ());             return "";         }         ///         ///Read Cookie value         ///         ///name         ///Cookie value          public static string GetCookie (string strName, string key)          {             if (HttpContext.Current.Request.Cookies! = null && httpcontext.current.request.cookies[strname]! = NULL && Amp Httpcontext.current.request.cookies[strname][key]! = null)                  return UrlDecode (Httpcontext.current.request.cookies[strname][key]. ToStRing ());              return "";         }         #endregion

C # Read and write cookie common functions

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.