Do not be familiar with the cookie operation can refer to.
Generally, a cookie is something that stores data for a visitor's computer, can treat a cookie as a table, has a table name, can have many rows, has two fields in each row, and key and Value,key are the only ones that can find the corresponding value by key.
Encapsulation Method:
#region Set cookies//<summary>//Set cookies///</summary>//<param N Ame= "key" > Key </param>//<param name= "value" > Value </param>///<param name= "CookieName" &G T;cookie name </param>//<param name= "cookiedays" >cookie reserved for how many days (default 3 days), you can use decimal notation </param> public s tatic void Setcookies (Httpresponsebase Response, Httprequestbase Request, string key, String value, String Cookiename,dou ble cookiedays=3) {HttpCookie cookie = request.cookies[cookiename]; Cookies. Expirationset = false; if (cookie = = null) {cookie = new HttpCookie (cookiename); Cookies. Values.add (key, value); } else {if (cookie. Values[key]! = null) {Cookie[key] = value; } else cookie. Values.add (key, value); } if(httpcontext.current! = null) {if (HttpContext.Current.Request.Url.DnsSafeHost.Contains ("kinpan.com")) { Cookies. Domain = "kinpan.com"; }}//cookie. Domain = configurationmanager.appsettings["Kinpandomain"]; Cookies. Path = "/"; Cookies. Expires = DateTime.Now.AddDays (cookiedays); Response.Cookies.Remove (CookieName); RESPONSE.COOKIES.ADD (cookie); } #endregion #region Delete cookies//<summary>///delete cookies, we do not have permission to delete them directly, but create a new cookie with the same name, set to Browser will detect and delete cookies with the same name. </summary>//<param name= "cookiename" >cookie name </param> public static void Deletecook IE (httpresponsebase response,string cookiename) {if (cookiename. HasValue ()) {HttpCookie acookie = new HttpCookie (cookiename); Acookie.expires = DateTime.Now.AddDays (-1); RESPONSE.COOKIES.ADD (Acookie); }} #endregion #region get the entire cookie///<summary>//Get the entire cookie///</S ummary>//<param name= "CookieName" ></param>///<returns></returns> Publ IC Static HttpCookie GetCookie (Httprequestbase Request, string cookiename) {return httpcontext.current. Request.cookies[cookiename]; #endregion #region Get the value of the key in the cookie//<summary>///Get the value of the key in the cookie.//</S ummary>//<param name= "name" > Name </param>//<param name= "key" > Key </param> <returns> return key corresponding value </returns> public static string GetCookies (Httprequestbase Request, string name, St Ring key) {if (String.IsNullOrEmpty (name) | | String.IsNullOrEmpty (key)) {return string.empty; } else {HttpCookie cookie = request.cookies[name]; if (cookie = null && cookie[key]! = null) {String value = Cookie[key]. ToString (); return HttpContext.Current.Server.UrlDecode (value); } else {return string.empty; }}} #endregion
. Net MVC Cookie Manipulation Encapsulation method