Name

HttpCookie

Synopsis

Use this class to create a client-side cookie. The HttpCookie constructor takes a string representing the name of the cookie. After creating a cookie, you can add information to it in the form of name/value pairs by using the HttpCookieCollection.Add() method as follows: objCookies.Values.Add("Name", "John"). Values can be retrieved by using their name with a syntax like strName = objCookies.Values("Name").

To send the cookie to the client browser as part of the HTTP response, use the AppendCookie() method of the HttpResponse class. This method stores the cookie on the client browser. You can then retrieve a cookie from the HttpResponse class’s cookie collection on other pages by using the cookie name, as in Response.Cookies("NameList"). To ensure compatibility with all browsers, you should not store more than 4096 bytes in a single cookie.

To make a cookie persist between sessions, set the Expires property for the HttpCookie to a date in the future. You can also set the Secure property to True to restrict the cookie to Secure Socket Layer (SSL) transmission. A cookie is usually considered less secure than Application or Session state variables, as information is maintained on the client and transmitted back and forth continuously.

Public NotInheritable Class HttpCookie
                  ' Public Constructors
   Public Sub New(ByVal name As String) 
   Public Sub New(ByVal name As String, ByVal value As String) 
' Public Instance Properties
   Public Property Domain As String Public ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.