HttpCookie

HttpCookie

System.Web (system.web.dll)sealed class

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 much less secure than Application or Session state variables, as information is maintained on the client and transmitted back and forth continuously.

public sealed class HttpCookie { // Public Constructors    public HttpCookie(string name);    public HttpCookie(string name, string value); // Public Instance Properties    public string Domain{set; get; }    public DateTime Expires{set; get; }    public bool HasKeys{get; }    public string Name{set; get; }    public string Path{set; get; }    public bool Secure{set; get; }    public string this[string key]{set; get; }    public string Value{set; get; }    public NameValueCollection Values{get; } }

Returned By

HttpCookieCollection.{Get( ), this}, System.Web.Security.FormsAuthentication.GetAuthCookie( )

Passed To

HttpCookieCollection.{Add( ), Set( )}, HttpResponse.{AppendCookie( ), SetCookie( )}



ASP. NET in a Nutshell
ASP.NET in a Nutshell, Second Edition
ISBN: 0596005202
EAN: 2147483647
Year: 2003
Pages: 873

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net