Export (0) Print
Expand All

HttpResponse.Cookies Property

Gets the response cookie collection.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public HttpCookieCollection Cookies { get; }
/** @property */
public HttpCookieCollection get_Cookies ()

public function get Cookies () : HttpCookieCollection

Property Value

The response cookie collection.

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.

TopicLocation
How to: Write a CookieBuilding ASP .NET Web Applications
How to: Delete a CookieBuilding ASP .NET Web Applications
How to: Write a CookieBuilding ASP .NET Web Applications
How to: Delete a CookieBuilding ASP .NET Web Applications

The following code 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);
   

HttpCookie myCookie = new HttpCookie("LastVisit");
DateTime now = DateTime.get_Now();

myCookie.set_Value(now.ToString());
myCookie.set_Expires(now.AddHours(1));

get_Response().get_Cookies().Add(myCookie);

var myCookie : HttpCookie = new HttpCookie("LastVisit")
var now : DateTime = DateTime.Now

myCookie.Value = now.ToString()
myCookie.Expires = now.AddHours(1)

Response.Cookies.Add(myCookie)
   

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft