This documentation is archived and is not being maintained.

HttpCookieCollection.Add Method

Adds the specified cookie to the cookie collection.

[Visual Basic]
Public Sub Add( _
   ByVal cookie As HttpCookie _
)
[C#]
public void Add(
 HttpCookie cookie
);
[C++]
public: void Add(
 HttpCookie* cookie
);
[JScript]
public function Add(
   cookie : HttpCookie
);

Parameters

cookie
The HttpCookie to add to the collection.

Remarks

Any number of cookie collections can exist within an application, but only the collection referenced by the intrinsic Cookies object is sent to the client.

Example

The following example creates a new cookie collection and a new cookie named "LastVisit", sets the value of the cookie to the current date and time, and adds the cookie to the new collection.

[Visual Basic] 
Dim MyCookieCollection as New HttpCookieCollection()
 Dim MyCookie As New HttpCookie("LastVisit")
 MyCookie.Value = DateTime.Now().ToString()
 MyCookieCollection.Add(MyCookie)
    

[C#] 
HttpCookieCollection MyCookieCollection = new HttpCookieCollection();
 HttpCookie MyCookie = new HttpCookie("LastVisit");
 MyCookie.Value = DateTime.Now.ToString();
 MyCookieCollection.Add(MyCookie);
    

[C++] 
HttpCookieCollection* MyCookieCollection = new HttpCookieCollection();
 HttpCookie* MyCookie = new HttpCookie(S"LastVisit");
 MyCookie->Value = DateTime::Now.ToString();
 MyCookieCollection->Add(MyCookie);
    

[JScript] 
var myCookieCollection : HttpCookieCollection = new HttpCookieCollection()
var myCookie : HttpCookie = new HttpCookie("LastVisit")
myCookie.Value = DateTime.Now.ToString()
myCookieCollection.Add(myCookie)

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpCookieCollection Class | HttpCookieCollection Members | System.Web Namespace

Show: