HttpResponse.Cookies Property
Assembly: System.Web (in system.web.dll)
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.
| Topic | Location |
|---|---|
| How to: Write a Cookie | Building ASP .NET Web Applications |
| How to: Delete a Cookie | Building ASP .NET Web Applications |
| How to: Write a Cookie | Building ASP .NET Web Applications |
| How to: Delete a Cookie | Building 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.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.