This class is a container that holds cookies and organizes them by URI. You can add a Cookie or CookieCollection to a container using the simplest forms of the Add( ) method, or you can use the forms of the Add( ) method that take a System.Uri argument. You can retrieve all the cookies for a given URI using the GetCookies( ) method.

public class CookieContainer {
// Public Constructors
   public CookieContainer( );
   public CookieContainer(int capacity);
   public CookieContainer(int capacity, int perDomainCapacity, int maxCookieSize);
// Public Static Fields
   public const int DefaultCookieLengthLimit;         
// =4096
   public const int DefaultCookieLimit;  
// =300
   public const int DefaultPerDomainCookieLimit;      
// =20
                  // Public Instance Properties
   public int Capacity{set; get; }
   public int Count{get; }
   public int MaxCookieSize{set; get; }
   public int PerDomainCapacity{set; get; }
// Public Instance Methods
   public void Add(Cookie cookie);
   public void Add(CookieCollection cookies);
   public void Add(Uri uri, Cookie cookie);
   public void Add(Uri uri, CookieCollection cookies);
   public string GetCookieHeader(Uri uri);
   public CookieCollection GetCookies(Uri uri);
   public void SetCookies(Uri uri, string cookieHeader);

Returned By


Passed To


Get C# in a Nutshell, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.