HttpResponse.AppendCookie(HttpCookie) Metod

Definition

Lägger till en HTTP-cookie i den inbyggda cookiesamlingen.

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

Parametrar

cookie
HttpCookie

Att HttpCookie lägga till i utdataströmmen.

Undantag

En cookie läggs till efter att HTTP-huvudena har skickats.

Exempel

I följande exempel skapas en ny cookie med namnet LastVisit, anger värdet för cookien till aktuellt datum och tid och lägger till cookien i den aktuella cookiesamlingen. Alla cookies i cookiesamlingen skickas till klienten i Set-Cookie rubriken med HTTP-utdataströmmen.

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

Dim MyCookie As New HttpCookie("LastVisit")
 MyCookie.Value = CStr(DateTime.Now())
 Response.AppendCookie(MyCookie)
    

Gäller för