This element enables you to manage how HTTP cookies are handled in HTTP requests and responses.
Attributes and Elements
The following sections describe attributes, child elements, and parent elements.
Defines the binding capabilities of the custom binding.
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 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.
<configuration> <system.serviceModel> <bindings> <!-- configure a custom binding --> <customBinding> <binding name="CustomBinding1"> <httpCookieContainer /> <httpTransport /> </binding> </customBinding> </bindings> </system.serviceModel> </configuration>