This documentation is archived and is not being maintained.

CookieContainer.Add Method (Cookie)

.NET Framework 1.1

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

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


The Cookie to be added to the CookieContainer.


Exception Type Condition
ArgumentNullException cookie is a null reference (Nothing in Visual Basic)
ArgumentException domain for cookie is a null reference (Nothing in Visual Basic)
CookieException cookie is larger than maxCookieSize


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 given 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