Export (0) Print
Expand All
1 out of 8 rated this helpful - Rate this topic

CookieContainer Class

Provides a container for a collection of CookieCollection objects.

System.Object
  System.Net.CookieContainer

Namespace:  System.Net
Assembly:  System (in System.dll)
'Declaration
<SerializableAttribute> _
Public Class CookieContainer

The CookieContainer type exposes the following members.

  NameDescription
Public methodSupported by Portable Class LibraryCookieContainerInitializes a new instance of the CookieContainer class.
Public methodCookieContainer(Int32)Initializes a new instance of the CookieContainer class with a specified value for the number of Cookie instances that the container can hold.
Public methodCookieContainer(Int32, Int32, Int32)Initializes a new instance of the CookieContainer class with specific properties.
Top
  NameDescription
Public propertySupported by Portable Class LibraryCapacityGets and sets the number of Cookie instances that a CookieContainer can hold.
Public propertySupported by Portable Class LibraryCountGets the number of Cookie instances that a CookieContainer currently holds.
Public propertySupported by Portable Class LibraryMaxCookieSizeRepresents the maximum allowed length of a Cookie.
Public propertySupported by Portable Class LibraryPerDomainCapacityGets and sets the number of Cookie instances that a CookieContainer can hold per domain.
Top
  NameDescription
Public methodAdd(Cookie)Adds a Cookie to a CookieContainer. This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with.
Public methodAdd(CookieCollection)Adds the contents of a CookieCollection to the CookieContainer.
Public methodSupported by Portable Class LibraryAdd(Uri, Cookie)Adds a Cookie to the CookieContainer for a particular URI.
Public methodSupported by Portable Class LibraryAdd(Uri, CookieCollection)Adds the contents of a CookieCollection to the CookieContainer for a particular URI.
Public methodSupported by Portable Class LibraryEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetCookieHeaderGets the HTTP cookie header that contains the HTTP cookies that represent the Cookie instances that are associated with a specific URI.
Public methodSupported by Portable Class LibraryGetCookiesGets a CookieCollection that contains the Cookie instances that are associated with a specific URI.
Public methodSupported by Portable Class LibraryGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySetCookiesAdds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI.
Public methodSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public fieldStatic memberSupported by Portable Class LibraryDefaultCookieLengthLimitRepresents the default maximum size, in bytes, of the Cookie instances that the CookieContainer can hold. This field is constant.
Public fieldStatic memberSupported by Portable Class LibraryDefaultCookieLimitRepresents the default maximum number of Cookie instances that the CookieContainer can hold. This field is constant.
Public fieldStatic memberSupported by Portable Class LibraryDefaultPerDomainCookieLimitRepresents the default maximum number of Cookie instances that the CookieContainer can reference per domain. This field is constant.
Top

A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

An instance of the Cookie class is added to the container based on its originating URI. It is added to an internal CookieCollection associated with the URI. A Cookie is retrieved from the container based on the URI as a CookieCollection, or as a string that can be used to submit HTTP WebRequests.

The CookieContainer has three properties that govern the volume of the content of the container: Capacity, MaxCookieSize, and PerDomainCapacity. These values have the default settings of 300, 4096, and 20 respectively. When a Cookie is added to the container, these properties are used to determine whether a Cookie already contained in the CookieContainer should be discarded to make room for the new one. The CookieContainer keeps track of each addition to ensure that neither the Capacity nor the PerDomainCapacity limits are exceeded. If one or both are exceeded, then Cookie instances held by the CookieContainer are removed. First, any expired Cookie is removed. If further capacity must be recaptured, then the least-recently used CookieCollection is purged.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.