System.Web Namespace HttpResponse Class
Gets the response cookie collection.
[ VB ]
Public ReadOnly Property Cookies As HttpCookieCollection
[ C# ]
public HttpCookieCollection Cookies {get;}
[ C++ ]
public: __property HttpCookieCollection* get_Cookies ( );
[ JScript ]
public function get Cookies ( ) : HttpCookieCollection;
The response cookie collection.
The cookie collection accessed through Response.Cookies contains cookies generated on the server and transmitted to the client in the Set-Cookie header.
Response.Cookies is also the syntax used to set the value of a cookie. If the specified cookie does not exist, it is created. If the cookie exists, it takes the new value and the old value is discarded.
The following example creates a new cookie named LastVisit, sets the value of the cookie to the current date and time, and adds the cookie to the current cookie collection. All cookies in the cookie collection are sent to the client in the Set-Cookie header with the HTTP output stream.
HttpCookie myCookie = new HttpCookie ( "LastVisit" );
DateTime now = DateTime.Now;
myCookie.Value = now.ToString ( );
myCookie.Expires = now.AddHours ( 1 );
Response.Cookies.Add ( myCookie );
Dim myCookie As New HttpCookie ( "LastVisit" )
Dim now As DateTime = DateTime.Now
myCookie.Value = now.ToString ( )
myCookie.Expires = now.AddHours ( 1 )
Response.Cookies.Add ( myCookie ) |
|
C# |
VB |
HttpResponse Members