Export (0) Print
Expand All

CookieContainer Class

Provides a container for a collection of CookieCollection objects.

System.Object
  System.Net.CookieContainer

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

public sealed class CookieContainer

The CookieContainer type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneCookieContainerInitializes a new instance of the CookieContainer class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneCapacityGets the number of Cookie objects this CookieContainer can contain.
Public propertySupported by Silverlight for Windows PhoneCountGets the number of Cookie objects this CookieContainer contains.
Public propertySupported by Silverlight for Windows PhoneMaxCookieSizeGets the maximum cookie length for cookies in the CookieContainer.
Public propertySupported by Silverlight for Windows PhonePerDomainCapacityGets and sets the number of Cookie instances that a CookieContainer can hold per domain.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneAdd(Uri, Cookie)Adds the specified Cookie with the specified Uniform Resource Identifier (URI) to this CookieContainer.
Public methodSupported by Silverlight for Windows PhoneAdd(Uri, CookieCollection)Adds the contents of the specified CookieCollection with the specified Uniform Resource Identifier (URI) to this CookieContainer.
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetCookieHeaderGets the HTTP cookie header that contains cookies pertaining to the specified Uniform Resource Identifier (URI).
Public methodSupported by Silverlight for Windows PhoneGetCookiesGets the CookieCollection associated with the specified Uniform Resource Identifier (URI).
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSetCookiesCreates cookie instances for the cookies specified in the HTTP cookie header and adds them to the CookieContainer associated with the specified Uniform Resource Identifier (URI).
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public fieldStatic memberSupported by Silverlight for Windows PhoneDefaultCookieLengthLimitRepresents the default maximum size, in bytes, of the Cookie objects that the CookieContainer can hold. This field is constant.
Public fieldStatic memberSupported by Silverlight for Windows PhoneDefaultCookieLimitRepresents the default maximum number of Cookie objects that the CookieContainer can hold. This field is constant.
Public fieldStatic memberSupported by Silverlight for Windows PhoneDefaultPerDomainCookieLimitRepresents the default maximum number of Cookie objects that the CookieContainer can reference per domain. This field is constant.
Top

A CookieContainer provides storage for CookieCollection objects on HttpWebRequest objects through the HttpWebRequest.CookieContainer property. The CookieContainer creates an internal CookieCollection to store cookies associated with a particular Uniform Resource Identifier (URI). A Cookie is retrieved from the container based on its URI as a CookieCollection, or as a string that can be used to submit with HTTP requests.

You must always create a CookieContainer to send with a request if you want cookies to be returned on the response. This is also true for HTTPOnly cookies, which you cannot retrieve.

The CookieContainer has three properties that specify the volume of the content of the container: Capacity, MaxCookieSize, and PerDomainCapacity. These properties have the default values of 300, 4096, and 20 respectively. When a Cookie is added to the container, these properties are used to determine whether a Cookie is already contained in the CookieContainer and whether one or more Cookie objects should be discarded to make room for the new one. The CookieContainer keeps track of each addition to make sure that neither the CookieContainer 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 additional capacity must be recaptured, then the least-recently-used CookieCollection is purged. If you attempt to add a cookie that already exists, that cookie will be overwritten.

The following example shows how to use the Add method.


request.CookieContainer.Add(new Uri("http://api.search.live.net"),
    new Cookie("id", "1234"));


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft