Cookie writing and reading

xiaoxiao2021-03-06  117

private void SaveCookie (string CookieName, string CookieValue) {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 OnInit (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 Joe");} private void Button2_Click (object sender, System. Eventargs e) {response.write (GetCookie ("MyCookie");

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

New Post(0)