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 the browser will be discarded if it is disabled.
Cookie in ASP. NET: Method for creating a Cookie (2)
HttpCookie aCookie = new HttpCookie ("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); Cookies 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"]; cookie in ASP. NET: Modify and delete Cookie
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.
This post comes from the group music community-http://q.yesky.com/group/review-18114556.html