Question

I'm looking for a good example of storing data in a cookie using ASP.NET. Could someone show me an example?

Was it helpful?

Solution

OTHER TIPS

MSDN is quite your friend : http://msdn.microsoft.com/en-us/library/78c837bd.aspx

Until then :

C#:  
Response.Cookie["cookie_name"] = "value";

VB:  
Response.Cookie("cookie_name") = "value";

How to Create a cookie

HttpCookie mycookie = new HttpCookie("mycookie");
mycookie.Value = "chocolate chip please.";
Response.Cookies.Add(mycookie);

How to Read a cookie

HttpCookie mycookie = Request.Cookies["mycookie"];
Response.Write("Your cookie is: " + mycookie.Value);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top