ASP. NET Cookies: Create Cookie Method (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 drive and the browser shutdown will be discarded.
ASP. NET Cookies: Create Cookie Method (2)
HttpCookie acookie = new HttpCookie ("lastvisit");
//Last access time
Acookie.value = DateTime.Now.ToString ();
acookie.expires = DateTime.Now.AddDays (1);
Response.Cookies.Add (Acookie);
ASP. NET Cookies: Access Cookie Method (1)
if (request.cookies["userName"]!= null)
Label1.Text = Server.HTMLEncode (request.cookies["UserName"). Value);
Access Cookie Method (2)
if (request.cookies["userName"]!= null) {
HttpCookie acookie = request.cookies["UserName"];
Label1.Text = Server.HTMLEncode (Acookie.value);
}
ASP. NET cookies: Creating a multivalued cookie method (1)
response.cookies["UserInfo" ["userName"] = "admin";
response.cookies["UserInfo" ["lastvisit"] = DateTime.Now.ToString ();
response.cookies["UserInfo"]. Expires = DateTime.Now.AddDays (1);
ASP. NET cookies: Creating a multivalued Cookie method (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);
ASP. NET cookies: Read multivalued cookies
HttpCookie acookie = request.cookies["UserInfo"];
string username=acookie.values["UserName"];
string lastvisit=acookie.values["lastvisit"];
ASP. NET cookies: modifying and deleting cookies
cannot modify or delete cookies directly, only a new cookie can be created and sent to the client to implement modify or delete cookies.