Add Method (Uri, Cookie)
Collapse the table of content
Expand the table of content

CookieContainer.Add Method (Uri, Cookie)

 

Adds a Cookie to the CookieContainer for a particular URI.

Namespace:   System.Net
Assembly:  System (in System.dll)

public void Add(
	Uri uri,
	Cookie cookie
)

Parameters

uri
Type: System.Uri

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

cookie
Type: System.Net.Cookie

The Cookie to be added to the CookieContainer.

Exception Condition
ArgumentNullException

uri is null or cookie is null.

CookieException

cookie is larger than maxCookieSize.

-or-

The domain for cookie is not a valid URI.

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft