The”Response.Cookies” command is used to create cookies.
Maximum 4 KB data can be store in a cookie.
Session timeout: 20 min Cache timeout: duration we have to specify. Cookie: for in memory cookie till browser opened For persistent cookie timeout is till expires property’s time . Application memory timeout: till appdomain exist
Forms authentication uses an authentication ticket that is created when a user logs on to a site, and then it tracks the user throughout the site. The forms authentication ticket is usually contained inside a cookie.
We can not destroy a cookie on user’s machine by Cookies.Remove method.
Instead we can set an already expired date for cookie expiration property.
if (this.Response.Cookies["MyCookie"] != null)
HttpCookie cookie = this.Response.Cookies["MyCookie"];
cookie.Expires = DateTime.Now.AddDays(-1);
HttpCookie cookieWebInfo = new HttpCookie(“WebInfo”);
CookieWebInfo[“Name”] = “DotnetFunda”;
// here CookieWebInfo is an object of class HttpCookie
CookieWebInfo[“Time”] = DateTime.Now.ToString();
cookieWebInfo.Expires = DateTime.Now.AddDays(10);
Here the HttpCookie class is under the System.Web namespace. Here ‘Expires’ sets the duration, when cookie expires.
Session Identifier is used to identify session. It has SessionId property. When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session or not. If not, a Session ID (120 – bit string) is generated by the web server and sent along with the response.