HttpResponse.Cookies Property
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Class Library
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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View