System.Net (system.dll)sealed class

This class represents an HTTP cookie, as standardized by RFC 2965 ( A cookie represents a simple name-value pair that is sent back by the HTTP User-Agent on each subsequent request to the URL host that set the cookie. The rules governing the visibility, scope, and lifetime of cookies is well documented in the RFC; see that document for details. The Cookie has properties defined on it corresponding to the settable values in the RFC: principally, the Value property sets the value of the cookie, and the Name property sets the name by which the cookie's value can be retrieved.

As a User-Agent, adding a Cookie to an HttpWebRequest is as simple as adding the Cookie instance to the HttpWebRequest.CookieContainer property. When you receive a response from an HTTP server, it may contain one or more cookies. Use the HttpWebResponse.Cookies collection to obtain the cookies that the HTTP server sent you.

Note that, as a User-Agent (the client), it is the .NET programmer's responsibility for maintaining all the semantics of the RFCthat is, the cookie must only be sent back to the host that set it, the cookie can only be sent back if it obeys the "path" prefix set on the cookie, and so forth. Failure to do so could result in different hosts viewing cookies that they didn't set, which is a potential security hole (albeit only if a host puts sensitive material into the cookie in the first place). None of this is implemented in the HttpWebRequest or Cookie types.

public sealed class Cookie {
// Public Constructors
   public Cookie( );
   public Cookie(string name, string value);
   public Cookie(string name, string value, string path);
   public Cookie(string name, string value, string path, string domain);
// Public Instance Properties
   public string Comment{set; get; }
   public Uri CommentUri{set; get; }
   public bool Discard{set; get; }
   public string Domain{set; get; }
   public bool Expired{set; get; }
   public DateTime Expires{set; get; }
   public string Name{set; get; }
   public string Path{set; get; }
   public string Port{set; get; }
   public bool Secure{set; get; }
   public DateTime TimeStamp{get; }
   public string Value{set; get; }
   public int Version{set; get; }
// Public Instance Methods
   public override bool Equals(object comparand);    
// overrides object
   public override int GetHashCode( );    
// overrides object
   public override string ToString( );    
// overrides object

Returned By


Passed To

CookieCollection.Add( ), CookieContainer.Add( )

    Part II: Programming with the .NET Framework
    Part IV: API Quick Reference
    Chapter 26. System