This documentation is archived and is not being maintained.

CookieContainer.Add Method (Uri, Cookie)

.NET Framework 1.1

Adds a Cookie to the CookieContainer for a particular URI.

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


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


Exception Type Condition
ArgumentNullException uri is a null reference (Nothing in Visual Basic)
ArgumentNullException cookie 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 the Cookie Version 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.


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