[Serializable] |
An instance of the Cookie class is added to the container based on its originating URI. It is added to an internal CookieCollection associated with the URI. A Cookie is retrieved from the container based on the URI as a CookieCollection, or as a string which can be used to submit HTTP WebRequests.
The CookieContainer has three properties that govern the volume of the content of the container: CookieContainer.Capacity, CookieContainer.MaxCookieSize, and CookieContainer.PerDomainCapacity. These values have the default settings of 300, 4096, and 20 respectively. When a Cookie is added to the container, these properties are used to determine whether a Cookie already contained in the CookieContainer should be discarded to make room for the new one. The CookieContainer keeps track of each addition to ensure that neither the CookieContainer.Capacity nor the CookieContainer.PerDomainCapacity limits are exceeded. If one or both are exceeded, then Cookie instances held by the CookieContainer are removed. First, any expired Cookie is removed. If further capacity must be recaptured, then the least-recently-used CookieCollection is purged.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the CookieContainer class. |
ctor #2 | Overloaded:.ctor(int capacity) Initializes a new instance of the CookieContainer class with a specified value for the number of Cookie instances the container can hold. |
ctor #3 | Overloaded:.ctor(int capacity, int perDomainCapacity, int maxCookieSize) Initializes a new instance of the CookieContainer class with specific properties. |
DefaultCookieLengthLimit | Represents the default maximum size, in bytes, of the Cookie instances the CookieContainer can hold. This field is constant. |
DefaultCookieLimit | Represents the default maximum number of Cookie instances the CookieContainer can hold. This field is constant. |
DefaultPerDomainCookieLimit | Represents the default maximum number of Cookie instances the CookieContainer can reference per domain. This field is constant. |
Capacity | Read-write Gets and sets the number of Cookie instances a CookieContainer can hold. |
Count | Read-only Gets the number of Cookie instances a CookieContainer currently holds. |
MaxCookieSize | Read-write Represents the maximum allowed length of a Cookie. |
PerDomainCapacity | Read-write Gets and sets the number of Cookie instances a CookieContainer can hold per domain. |
Add | Overloaded:Add(Cookie cookie) Adds a Cookie to a CookieContainer. This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with. |
Add | Overloaded:Add(CookieCollection cookies) Adds the contents of a CookieCollection to the CookieContainer. |
Add | Overloaded:Add(Uri uri, Cookie cookie) Adds a Cookie to the CookieContainer for a particular URI. |
Add | Overloaded:Add(Uri uri, CookieCollection cookies) Adds the contents of a CookieCollection to the CookieContainer for a particular URI. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetCookieHeader | Gets the HTTP cookie header containing the HTTP cookies representing the Cookie instances associated with a specific URI. |
GetCookies | Gets A CookieCollection containing the Cookie instances associated with a specific URI. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
SetCookies | Adds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public CookieContainer(); |
public CookieContainer( |
capacity
Exception Type | Condition |
---|---|
ArgumentException | capacity is less than or equal to zero |
capacity
perDomainCapacity
maxCookieSize
Exception Type | Condition |
---|---|
ArgumentException | perDomainCapacity is not equal to Int32.MaxValue and (perDomainCapacity is less than or equal to zero or perDomainCapacity is greater than capacity) |
ArgumentException | maxCookieSize is less than or equal to zero |
public const int DefaultCookieLengthLimit;
|
public const int DefaultCookieLimit;
|
public const int DefaultPerDomainCookieLimit;
|
public int Capacity {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | Capacity is less than or equal to zero or (value is less than CookieContainer.PerDomainCapacity and CookieContainer.PerDomainCapacity is not equal to Int32.MaxValue). |
CookieContainer.Capacity must be greater than or equal to CookieContainer.PerDomainCapacity. If you set CookieContainer.PerDomainCapacity and the current CookieContainer.Count of Cookie instances is less than the new value, the excess is removed from the container. Enough instances are removed to bring CookieContainer.Count below CookieContainer.Capacity as follows: if there are expired Cookie instances in scope they are cleaned up. If not, or if there are still more than the new value of CookieContainer.PerDomainCapacity, then the least recently used CookieCollection is found and removed from the container.
public int Count {get;}
|
public int MaxCookieSize {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | MaxCookieSize is less than or equal to zero |
public int PerDomainCapacity {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | PerDomainCapacity is less than or equal to zero or (PerDomainCapacity is greater than the maximum allowable number of cookies instances, 300, and is not equal to Int32.MaxValue) |
public void Add( |
cookie
Exception Type | Condition |
---|---|
ArgumentNullException | cookie is null |
ArgumentException | domain for cookie is null |
CookieException | cookie is larger than maxCookieSize |
public void Add( |
cookies
Exception Type | Condition |
---|---|
ArgumentNullException | cookies is null |
uri
cookie
Exception Type | Condition |
---|---|
ArgumentNullException | uri is null |
ArgumentNullException | cookie is null |
If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the Cookie Cookie.Domain property equal to ".local". Otherwise, make sure it matches the host name used in the URI.
If the Cookie Cookie.Version is Netscape, the Cookie.Path property of the Cookie, if not set explicitly, is derived from the URI and is the complete path from the URI, including the page name.
If the CookieContainer.Count property equals the CookieContainer.Capacity property, one or more Cookie instances are removed from the container before adding the cookie parameter. Enough Cookie instances are removed to bring CookieContainer.Count below CookieContainer.Capacity as follows: if there are expired instances in scope they are cleaned up. If not, then the least recently used CookieCollection is found and removed from the container.
public void Add( |
uri
cookies
Exception Type | Condition |
---|---|
ArgumentNullException | uri is null |
ArgumentNullException | cookies is null |
If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the Cookie Cookie.Domain property equal to ".local". Otherwise, make sure it matches the host name used in the URI.
If CookieContainer.Count equals CookieContainer.Capacity, one or more Cookie instances is removed from the container before adding the cookie parameter. Enough Cookie instances are removed to bring CookieContainer.Count below CookieContainer.Capacity as follows: if there are expired instances in scope they are cleaned up. If not, then the least recently used CookieCollection is found and removed from the container.
~CookieContainer(); |
uri
Exception Type | Condition |
---|---|
ArgumentNullException | uri is null |
This string is not in the correct format for use as the second parameter of the CookieContainer.SetCookies method.
public CookieCollection GetCookies( |
uri
Exception Type | Condition |
---|---|
ArgumentNullException | uri is null |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
uri
cookieHeader
Exception Type | Condition |
---|---|
ArgumentNullException | uri is null |
ArgumentNullException | cookieHeader is null |
public virtual string ToString(); |