System.Web Namespace HttpCookieCollection Class
Adds the specified cookie to the cookie collection.
[ VB ]
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
);
- cookie
- The HttpCookie to add to the collection.
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.
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.
[ VB ]
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 );
HttpCookieCollection Members