HttpResponse.Cookies Property
Gets the response cookie collection.
[Visual Basic] Public ReadOnly Property Cookies As HttpCookieCollection [C#] public HttpCookieCollection Cookies {get;} [C++] public: __property HttpCookieCollection* get_Cookies(); [JScript] public function get Cookies() : HttpCookieCollection;
Property Value
The response cookie collection.
Remarks
ASP.NET includes two intrinsic cookie collections. The collection accessed through the Cookies collection of HttpRequest contains cookies transmitted by the client to the server in the Cookie header. The collection accessed through the Cookies collection of HttpResponse contains new cookies created on the server and transmitted to the client in the Set-Cookie header.
Example
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.
[Visual Basic] 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#] HttpCookie MyCookie = new HttpCookie("LastVisit"); DateTime now = DateTime.Now; MyCookie.Value = now.ToString(); MyCookie.Expires = now.AddHours(1); Response.Cookies.Add(MyCookie); [C++] HttpCookie* MyCookie = new HttpCookie(S"LastVisit"); DateTime now = DateTime::Now; MyCookie->Value = now.ToString(); MyCookie->Expires = now.AddHours(1); Response->Cookies->Add(MyCookie); [JScript] var myCookie : HttpCookie = new HttpCookie("LastVisit") var now : DateTime = DateTime.Now myCookie.Value = now.ToString() myCookie.Expires = now.AddHours(1) Response.Cookies.Add(myCookie)
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HttpResponse Class | HttpResponse Members | System.Web Namespace