Cookies

I provide a general code to explain how to set and get a cookie in ASP.Net


protected void btnSubmit_Click(object sender, EventArgs e)
{
HttpCookie testCookie = new HttpCookie("TestCookie");
testCookie.Path = "/";
testCookie.Expires = Convert.ToDateTime("March 14 2000");
testCookie.Value = "Nikhil Agarwal";
Response.SetCookie(testCookie);

HttpCookie testCookieValue = new HttpCookie("TestCookie");
if (testCookieValue != null)
{
Response.Write(testCookieValue.Value.ToString());

}
}


Reference: http://mycodediary.blogspot.com/2009/01/what-is-cookies.html


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: