Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Cookie Constructor (String, String)

Initializes a new instance of the Cookie class with a specified Name and Value.

Namespace:  System.Net
Assembly:  System (in System.dll)
'Declaration
Public Sub New ( _
	name As String, _
	value As String _
)

Parameters

name
Type: System.String

The name of a Cookie. The following characters must not be used inside name: equal sign, semicolon, comma, newline (\n), return (\r), tab (\t), and space character. The dollar sign character ("$") cannot be the first character.

value
Type: System.String

The value of a Cookie. The following characters must not be used inside value: semicolon, comma.

ExceptionCondition
CookieException

The name parameter is Nothing.

-or-

The name parameter is of zero length.

-or-

The name parameter contains an invalid character.

-or-

The value parameter is Nothing .

-or -

The value parameter contains a string not enclosed in quotes that contains an invalid character.

The default for the value parameter uses the empty string ("").

The value parameter for a Cookie must not be a Nothing reference (Nothing in Visual Basic). The following characters are reserved and cannot be passed in the value parameter unless the string passed in the value parameter is enclosed in double quotes: semicolon, comma. So the following example constructor would succeed but when you try to add this Cookie to a CookieContainer instance with the Add or Add methods the operation will fail and throw an exception:

System.Net.Cookie cookie = new System.Net.Cookie("contoso", "123,456", "");

However, the following constructor with these special characters escaped will create a Cookie that can be added to a CookieContainer instance:

System.Net.Cookie cookie = new System.Net.Cookie("contoso", "\"123,456\"");

The comma character is used as a delimiter between separate cookies on the same line.

.NET Framework

Supported in: 4.5.1, 4.5, 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

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.