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

CookieContainer.Add Method (Uri, CookieCollection)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Sub Add( _
   ByVal uri As Uri, _
   ByVal cookies As CookieCollection _
public void Add(
 Uri uri,
 CookieCollection cookies
public: void Add(
 Uri* uri,
 CookieCollection* cookies
public function Add(
   uri : Uri,
 cookies : CookieCollection


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


Exception Type Condition
ArgumentNullException uri is a null reference (Nothing in Visual Basic)
ArgumentNullException cookies is a null reference (Nothing in Visual Basic)


If you add a Cookie instance for just one specific host, don't 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 Cookie Domain 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.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

CookieContainer Class | CookieContainer Members | System.Net Namespace | CookieContainer.Add Overload List | Cookie | CookieCollection | CookieContainer | CookieException

© 2016 Microsoft