Cookies (instances of HttpCookie) provide a way to store user-specific information in a WEB application. For example, when a user accesses your site, you can use cookies to store user preferences or other information. When the user accesses your Web site again, the application can retrieve previously stored information.
Asp. NET cookies: Creating cookie Methods (1)
response.cookies["UserName"]. Value = "admin";
response.cookies["UserName"]. Expires = DateTime.Now.AddDays (1);
If no expiration time is set, the cookie information is not written to the user's hard disk, and the browser shutdown is discarded.
Asp. NET cookies: Creating Cookie Methods (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 Acooki