A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.
Create a Cookie
You can add cookies to the Cookies collection in a number of ways. The following example shows two methods to write cookies:
Response.Cookies["UserName"].Value = "John"; Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1); HttpCookie aCookie = new HttpCookie("LastVisit"); aCookie.Value = DateTime.Now.ToString(); aCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(aCookie);
if(Request.Cookies["UserName"] != null)
Label1.Text = Server.HtmlEncode(Request.Cookies["UserName"].Value);
Retrieve a Cookie