Editar

Compartilhar via


HttpResponse.SetCookie(HttpCookie) Method

Definition

Because the HttpResponse.SetCookie method is intended for internal use only, you should not call it in your code. Instead, you can call the HttpResponse.Cookies.Set method, as the following example shows.
Updates an existing cookie in the cookie collection.

public:
 void SetCookie(System::Web::HttpCookie ^ cookie);
public void SetCookie (System.Web.HttpCookie cookie);
member this.SetCookie : System.Web.HttpCookie -> unit
Public Sub SetCookie (cookie As HttpCookie)

Parameters

cookie
HttpCookie

The cookie in the collection to be updated.

Exceptions

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

Examples

The following example updates the value of an existing cookie.

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

MyCookie.Value = CStr(DateTime.Now())
    Response.Cookies.Set(MyCookie)
    

Applies to

See also