HttpResponse.SetCookie Method (HttpCookie)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

This API supports the product infrastructure and is not intended to be used directly from your code.

Updates an existing cookie in the cookie collection.

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

public void SetCookie(
	HttpCookie cookie
)

Parameters

cookie
Type: System.Web.HttpCookie

The cookie in the collection to be updated.

Exception Condition
HttpException

The cookie is set after the HTTP headers have been sent.

HttpException

Attempted to set the cookie after the HTTP headers were sent.

HttpException

The cookie is set after the HTTP headers have been sent.

HttpException

Attempted to set the cookie after the HTTP headers were sent.

The following example updates the value of an existing cookie.

MyCookie.Value = DateTime.Now.ToString();
 Response.Cookies.Add(MyCookie);

.NET Framework
Available since 1.1
Return to top
Show: