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);} ///
} #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");}