Cookies in asp.net - All about HttpCookies

Cookies in asp.net 


Asp.net cookies is a small piece of information stored on the client machine.The HttpCookie class is under System.Web namespace. It contains properties and methods necessary to work with individual cookies.Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. Length of the text stored in cookies is 4096(4kb) in general but could vary from browser to browser.

Cookies are small text files that a is transferred by the site you visit or internet service provider and saved to your computer's hard drive with the help of web browser. You need to allow your site to save the file to your system. The site/ service provider recognizes your web browser and capture, remembers and stores specific information.

With the help of cookies, only the website can remember your Wishlist items, products stored in your shopping cart, your recent activity list and preferences that ultimately help us improve our service and your browsing experience. With the help of cookies, we compile site traffic and site visitors’ interaction data.

Remember, third party sites are not provided your personal information stored with us, but we may use the information and contact external websites to improve the services we offer and assist you better.

Cookies can be enabled or disabled through your browser settings. In case you face any issues look for browser help menu and search how to modify cookies settings. Turning off cookies will refrain you from features that help improve site experience and services provided to you. You can still place orders over the telephone by contacting customer service.


Cookies in asp.net



Persistent and Non-persistent cookies in ASP.NET



There two type of cookies in ASP.NET

Persistent cookies: Asp.net cookies are stored on your computer hard disk.They stay on your hard disk and can be accessed by web servers until they are deleted or have expired.

public void PersistentCookies(string name, string value)
{
 HttpCookie cookie = new HttpCookie(name);
 cookie.Value = value;
 cookie.Expires = Convert.ToDateTime("12/12/2008");
 Response.Cookies.Add(cookie);
}



Non-persistent cookies: Asp.net cookies are saved only while your web browser is running.  They can be used by a web server only until you close your browser.They are not saved on your disk.


public void NonPersistentCookies(string name, string value)

{
    HttpCookie cookie = new HttpCookie(name);
    cookie.Value = value;
    Response.Cookies.Add(cookie);
}


EmoticonEmoticon