Cookie (HttpCookie instance) provides a method to store user-specific information in Web applications. For example, when a user accesses your site, you can use cookies to store user preferences or other information. When the user visits your website again, the application can retrieve the previously stored information.
Cookie in ASP. NET: Method for creating a Cookie (1)
- Response.Cookies["userName"].Value = “admin";
- Response.Cookies[“userName”].Expires = DateTime.Now.AddDays(1);
// If no expiration time is set, the Cookie information will not be written to the user's hard disk, and will be discarded if the browser is closed.
Cookie in ASP. NET: Method for creating a Cookie (2)
- HttpCookie aCookie =NewHttpCookie ("lastVisit ");// Last access time
- ACookie. Value = DateTime. Now. ToString ();
- ACookie. Expires = DateTime. Now. AddDays (1 );
- Response. Cookies. Add (aCookie );
Cookie in ASP. NET: Access Cookie method (1)
- If(Request. Cookies ["UserName"]! =Null)
- Label1.Text = Server. HtmlEncode (Request. Cookies ["UserName"]. Value); Cookie Access Method (2)
- If(Request. Cookies ["UserName"]! =Null)
- {
- HttpCookie aCookie = Request. Cookies ["UserName"];
- Label1.Text = Server. HtmlEncode (aCookie. Value );
- }
Cookie in ASP. NET: Method for creating multi-value cookies (1)
- Response.Cookies["userInfo"]["userName"] = “admin";
- Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString();
- Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1);
Cookie in ASP. NET: Method for creating multi-value cookies (2)
- HttpCookie aCookie = new HttpCookie("userInfo");
- aCookie.Values["userName"] = “admin";
- aCookie.Values["lastVisit"] = DateTime.Now.ToString();
- aCookie.Expires = DateTime.Now.AddDays(1);
- Response.Cookies.Add(aCookie);
Cookie in ASP. NET: Read multi-value Cookie
- HttpCookie aCookie = Request.Cookies["userInfo"];
- string userName=aCookie.Values[“userName”];
- string lastVisit=aCookie.Values[“lastVisit”];
Cookies in ASP. NET: Modify and delete cookies
You cannot directly modify or delete a Cookie. You can create only one new Cookie and send it to the client to modify or delete the Cookie.
- Implementation of ASP. NET form Authentication
- An error occurred while submitting the asp.net Form using JQuery Form Ajax.
- Summary of ASP. NET installation and deployment problems
- Experience in running ASP. NET on APACHE
- ASP. NET Online Learning Resource Summary