HttpCookie Constructor (String, String) (System.Web)

Switch View :
ScriptFree
.NET Framework Class Library
HttpCookie Constructor (String, String)

Creates, names, and assigns a value to a new cookie.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic
Public Sub New ( _
	name As String, _
	value As String _
)
C#
public HttpCookie(
	string name,
	string value
)
Visual C++
public:
HttpCookie(
	String^ name, 
	String^ value
)
F#
new : 
        name:string * 
        value:string -> HttpCookie

Parameters

name
Type: System.String
The name of the new cookie.
value
Type: System.String
The value of the new cookie.
Examples

The following code example creates, names, and sets the value of a new cookie.

Visual Basic

Dim MyCookie As New HttpCookie("LastVisit", CStr(DateTime.Now()))
    


C#

HttpCookie MyCookie = new HttpCookie("LastVisit", 
    DateTime.Now.ToString());
    


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Reference

Community Content

MMPete
What is the default expiration for cookie created with this constructor?
What is the default expiration for cookie created with this constructor?