CookieContainer CookieContainer CookieContainer CookieContainer Class

Definition

Provides a container for a collection of CookieCollection objects.

public ref class CookieContainer
[System.Serializable]
public class CookieContainer
type CookieContainer = class
Public Class CookieContainer
Inheritance
CookieContainerCookieContainerCookieContainerCookieContainer
Attributes

Remarks

A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

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 that can be used to submit HTTP WebRequests.

The CookieContainer has three properties that govern the volume of the content of the container: Capacity, MaxCookieSize, and 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 Capacity nor the 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.

Constructors

CookieContainer() CookieContainer() CookieContainer() CookieContainer()

Initializes a new instance of the CookieContainer class.

CookieContainer(Int32) CookieContainer(Int32) CookieContainer(Int32) CookieContainer(Int32)

Initializes a new instance of the CookieContainer class with a specified value for the number of Cookie instances that the container can hold.

CookieContainer(Int32, Int32, Int32) CookieContainer(Int32, Int32, Int32) CookieContainer(Int32, Int32, Int32) CookieContainer(Int32, Int32, Int32)

Initializes a new instance of the CookieContainer class with specific properties.

Fields

DefaultCookieLengthLimit DefaultCookieLengthLimit DefaultCookieLengthLimit DefaultCookieLengthLimit

Represents the default maximum size, in bytes, of the Cookie instances that the CookieContainer can hold. This field is constant.

DefaultCookieLimit DefaultCookieLimit DefaultCookieLimit DefaultCookieLimit

Represents the default maximum number of Cookie instances that the CookieContainer can hold. This field is constant.

DefaultPerDomainCookieLimit DefaultPerDomainCookieLimit DefaultPerDomainCookieLimit DefaultPerDomainCookieLimit

Represents the default maximum number of Cookie instances that the CookieContainer can reference per domain. This field is constant.

Properties

Capacity Capacity Capacity Capacity

Gets or sets the number of Cookie instances that a CookieContainer can hold.

Count Count Count Count

Gets the number of Cookie instances that a CookieContainer currently holds.

MaxCookieSize MaxCookieSize MaxCookieSize MaxCookieSize

Represents the maximum allowed length of a Cookie.

PerDomainCapacity PerDomainCapacity PerDomainCapacity PerDomainCapacity

Gets or sets the number of Cookie instances that a CookieContainer can hold per domain.

Methods

Add(Cookie) Add(Cookie) Add(Cookie) Add(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(CookieCollection) Add(CookieCollection) Add(CookieCollection) Add(CookieCollection)

Adds the contents of a CookieCollection to the CookieContainer.

Add(Uri, Cookie) Add(Uri, Cookie) Add(Uri, Cookie) Add(Uri, Cookie)

Adds a Cookie to the CookieContainer for a particular URI.

Add(Uri, CookieCollection) Add(Uri, CookieCollection) Add(Uri, CookieCollection) Add(Uri, CookieCollection)

Adds the contents of a CookieCollection to the CookieContainer for a particular URI.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCookieHeader(Uri) GetCookieHeader(Uri) GetCookieHeader(Uri) GetCookieHeader(Uri)

Gets the HTTP cookie header that contains the HTTP cookies that represent the Cookie instances that are associated with a specific URI.

GetCookies(Uri) GetCookies(Uri) GetCookies(Uri) GetCookies(Uri)

Gets a CookieCollection that contains the Cookie instances that are associated with a specific URI.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SetCookies(Uri, String) SetCookies(Uri, String) SetCookies(Uri, String) SetCookies(Uri, String)

Adds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also