HttpResponse.AppendCookie(HttpCookie) Method

Definition

Adds an HTTP cookie to the intrinsic cookie collection.

C#
public void AppendCookie(System.Web.HttpCookie cookie);

Parameters

cookie
HttpCookie

The HttpCookie to add to the output stream.

Exceptions

A cookie is appended after the HTTP headers have been sent.

Examples

The following example creates a new cookie named LastVisit, sets the value of the cookie to the current date and time, and appends 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.

C#
HttpCookie MyCookie = new HttpCookie("LastVisit");
 MyCookie.Value = DateTime.Now.ToString();
 Response.AppendCookie(MyCookie);

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1