How to create a cookie and how to provide value to it?

Tripati_tutu
Posted by Tripati_tutu under ASP.NET category on | Points: 40 | Views : 1516
To create a cookie,
HttpCookie CookieName = new HttpCookie("Users");

To set values for the cookie,
CookieName.Values.Add("Questions", "DotNetFunda");
CookieName.Values.Add("Products", "ITFunda");

Suppose you want to add the cookie to the cookie collection, then
Response.Cookies.Add(CookieName);

To get the value stored in the cookie
Response.Write(CookieName.Value.ToString());

Suppose you want to retrive the specific cookie, then
Response.Write(CookieName["Products"].ToString());

Comments or Responses

Login to post response