ASP.Net Cookies

A cookie is a bit of info which can be read whenever the user visits the website.
Cookie is saved on client side.


Response.Cookies["userName"].Value = "John";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

HttpCookie cookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
Reading the Cookie
if(Request.Cookies["userName"] != null)
    Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);
Above text is taken from
https://msdn.microsoft.com/en-us/library/ms178194.aspx
Type of Cookies?
  1. Persist Cookie - A cookie with no expiry date is Persist Cookie
  2. Non-Persist Cookie - A cookie with expiry date is Non-Persist Cookie
State management is an art which retains user specific info between requests but most of the time the scope of info is global to entire app, To achieve the goal of state management in the app you may mix up the following client side state management options  
  • Control state
  • Hidden fields
  • ViewState
  • Query strings
For further question please mail: brainstormiert@gmail.com