<httpCookieContainer> (Silverlight)

This element enables you to manage how HTTP cookies are handled in HTTP requests and responses.


<httpCookieContainer />

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.



Child Elements


Parent Elements

Element Description

<binding> of <customBinding> (Silverlight)

Defines the binding capabilities of the custom binding.

Text Value


When this binding element is included in the <binding> of <customBinding> (Silverlight) element of a custom binding, you can specify an instance of CookieContainer to be used when issuing an HTTP request. Any cookies in the CookieContainer applicable to the request will automatically be included when the HTTP request is made, and any cookies that are returned as part of the HTTP response will automatically be placed in the CookieContainer.

The same CookieContainer instance can be used for multiple channels, which is often useful when one service is used to provide cookies for authentication and another service requires these authentication cookies provided by the first service. To gain access to the CookieContainer instance, call GetProperty on a channel constructed from a binding that included the <httpCookieContainer> binding element, using the IHttpCookieContainerManager type parameter.

Then, access the CookieContainer property. The property is null by default, signifying that no CookieContainer should be used.

Using the <httpCookieContainer> binding element to manage cookies is necessary only when you have registered an alternative HTTP stack using RegisterPrefix. The default browser-based HTTP stack in Silverlight version 4 automatically uses the browser’s cookie repository and does not require this mechanism. If you attempt to set a CookieContainer using this mechanism with the browser-based HTTP stack, the channel will throw an exception when attempting to issue an HTTP request.

The <httpCookieContainer> binding element works only with the <httpTransport> (Silverlight) and <httpsTransport> (Silverlight) transport binding elements.


The following code example shows how to specify in a <customBinding> (Silverlight) configuration that you need to manage cookies with a container when you have registered an alternative HTTP stack.

      <!-- configure a custom binding -->
        <binding name="CustomBinding1">
          <httpCookieContainer />
          <httpTransport />

See Also