Cookie writing and reading

xiaoxiao2021-03-06  111

Private Void Savecookie (String Cookiename) {httpcookie mycookie = new httpcookie (cookiename); DateTime now = datetime.now;

. // Set the cookie value myCookie.Value = CookieValue; // Set the cookie expiration date myCookie.Expires = now.AddYears (1);. If (this.Response.Cookies [CookieName] = null!) This.Response. Cookies.Remove (CookieName); // Add the cookie this.Response.Cookies.Add (myCookie);.} private string GetCookie (string CookieName) {HttpCookie myCookie = new HttpCookie (CookieName); myCookie = Request.Cookies [CookieName] ;

// read the cookie information and display it. If (mycookie! = Null) return mycookie.value; else return null;}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.Button1.Click = new System.EventHandler (this.Button1_Click); this.Button2.Click = new System.EventHandler (this.Button2_Click); this.Load = new system.eventhandler (this.page_load);

} #Endregion

Private void Button1_Click (Object Sender, System.EventArgs E) {Savecookie ("MyCookie", "Internet Langzi");}

Private void button2_click (object sender, system.eventargs e) {response.write ("mycookie");}

转载请注明原文地址:https://www.9cbs.com/read-101358.html

New Post(0)