How to Create a Cookie?

Cookie are one of several ways to store data about web site visitors during the time when web server and browser are not connected. Common use of cookies is to remember users between visits. Practically, cookie is a small text file sent by web server and saved by web browser on client machine.
The”Response.Cookies” command is used to create cookies.

What is Data limit that can be stored in a cookie?

Maximum 4 KB data can be store in a cookie.

What is session ,cache, cookie, application memory timeout?

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

What is Forms Authentication?

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.

How to destroy a cookie In ASP.NET?

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);

Write the code which will create a cookie containing the user name DotnetFunda and the current date to the user computer. Set the cookie as that remains on the user computer for 10 days?

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.

What is Session Identifier?

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.