Tuesday, May 3, 2011

Cookies in ASP.NET

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

From stackoverflow
  • Google says "How to Write a Cookie"

  • check this out

    Save Form Data With Cookies

    Chris Lively : Exactly what part of that link had anything at all to do with .Net?
  • 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";
    
    rick schott : Please update answer with this link, http://msdn.microsoft.com/en-us/library/78c837bd.aspx. Site is only in en-US right now.
  • 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);
    

0 comments:

Post a Comment