Edit

Share via


CookieContainer.Add Method

Definition

Adds a Cookie to a CookieContainer.

Overloads

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)

Adds the contents of a CookieCollection to the CookieContainer.

Add(Uri, Cookie)

Adds a Cookie to the CookieContainer for a particular URI.

Add(Uri, CookieCollection)

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

Add(Cookie)

Source:
CookieContainer.cs
Source:
CookieContainer.cs
Source:
CookieContainer.cs

Adds a Cookie to a CookieContainer. This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with.

public:
 void Add(System::Net::Cookie ^ cookie);
public void Add (System.Net.Cookie cookie);
member this.Add : System.Net.Cookie -> unit
Public Sub Add (cookie As Cookie)

Parameters

cookie
Cookie

The Cookie to be added to the CookieContainer.

Exceptions

cookie is null.

The domain for cookie is null or the empty string ("").

cookie is larger than maxCookieSize.

-or-

the domain for cookie is not a valid URI.

Remarks

If the Count property equals or exceeds the Capacity property, one or more Cookie instances are removed from the container before adding the cookie parameter. Enough Cookie instances are removed to bring Count below Capacity as follows: if there are expired instances in the given scope, they are cleaned up. If not, then the least recently used CookieCollection is found and removed from the container.

See also

Applies to

Add(CookieCollection)

Source:
CookieContainer.cs
Source:
CookieContainer.cs
Source:
CookieContainer.cs

Adds the contents of a CookieCollection to the CookieContainer.

public:
 void Add(System::Net::CookieCollection ^ cookies);
public void Add (System.Net.CookieCollection cookies);
member this.Add : System.Net.CookieCollection -> unit
Public Sub Add (cookies As CookieCollection)

Parameters

cookies
CookieCollection

The CookieCollection to be added to the CookieContainer.

Exceptions

cookies is null.

Remarks

If the Count property equals the Capacity property, one or more Cookie instances are removed from the container before adding the contents of the cookies parameter. Enough Cookie instances are removed to make room for cookies as follows: if there are expired instances, they are cleaned up. If not, or if more room is needed, then the least recently used CookieCollection is found and removed from the container.

See also

Applies to

Add(Uri, Cookie)

Source:
CookieContainer.cs
Source:
CookieContainer.cs
Source:
CookieContainer.cs

Adds a Cookie to the CookieContainer for a particular URI.

public:
 void Add(Uri ^ uri, System::Net::Cookie ^ cookie);
public void Add (Uri uri, System.Net.Cookie cookie);
member this.Add : Uri * System.Net.Cookie -> unit
Public Sub Add (uri As Uri, cookie As Cookie)

Parameters

uri
Uri

The URI of the Cookie to be added to the CookieContainer.

cookie
Cookie

The Cookie to be added to the CookieContainer.

Exceptions

uri is null or cookie is null.

cookie is larger than maxCookieSize.

-or-

The domain for cookie is not a valid URI.

Remarks

If you add a Cookie instance for just one specific host, do not set the Domain property of the Cookie instance. This is set automatically, based on the URI.

If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the CookieDomain property equal to ".local". Otherwise, make sure it matches the host name used in the URI.

If the Version property of a Cookie is Netscape, the 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 Count property equals the Capacity property, one or more Cookie instances are removed from the container before adding the cookie parameter. Enough Cookie instances are removed to bring Count below 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.

See also

Applies to

Add(Uri, CookieCollection)

Source:
CookieContainer.cs
Source:
CookieContainer.cs
Source:
CookieContainer.cs

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

public:
 void Add(Uri ^ uri, System::Net::CookieCollection ^ cookies);
public void Add (Uri uri, System.Net.CookieCollection cookies);
member this.Add : Uri * System.Net.CookieCollection -> unit
Public Sub Add (uri As Uri, cookies As CookieCollection)

Parameters

uri
Uri

The URI of the CookieCollection to be added to the CookieContainer.

cookies
CookieCollection

The CookieCollection to be added to the CookieContainer.

Exceptions

cookies is null.

The domain for one of the cookies in cookies is null.

One of the cookies in cookies contains an invalid domain.

Remarks

If you add a Cookie instance for just one specific host, do not set the Domain property of the Cookie instance. This is set automatically, based on the URI.

If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the CookieDomain property equal to ".local". Otherwise, make sure it matches the host name used in the URI.

If Count equals Capacity, one or more Cookie instances is removed from the container before adding the cookie parameter. Enough Cookie instances are removed to bring Count below 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.

See also

Applies to