CookieContainer.Add Method (Uri, Cookie)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Adds the specified Cookie with the specified Uniform Resource Identifier (URI) to this CookieContainer.

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

Syntax

'Declaration
Public Sub Add ( _
    uri As Uri, _
    cookie As Cookie _
)
public void Add(
    Uri uri,
    Cookie cookie
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

cookie is null.

ArgumentException

The domain for cookie is nulla null reference (Nothing in Visual Basic).

CookieException

cookie is larger than MaxCookieSize.

-or-

the domain for cookie is not a valid URI.

Remarks

If the specified cookie already exists in the container, then the cookie will be overwritten.

Examples

The following example shows how to use the Add method.

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

Version Information

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

Platforms

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