HttpCookieCollection.Add(HttpCookie) Metod

Definition

Lägger till den angivna cookien i cookiesamlingen.

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

Parametrar

cookie
HttpCookie

Att HttpCookie lägga till i samlingen.

Exempel

I följande exempel skapas en ny cookiesamling och en ny cookie med namnet "LastVisit", anger cookiens värde till aktuellt datum och tid och lägger till cookien i den nya samlingen.

HttpCookieCollection MyCookieCollection = new HttpCookieCollection();
 HttpCookie MyCookie = new HttpCookie("LastVisit");
 MyCookie.Value = DateTime.Now.ToString();
 MyCookieCollection.Add(MyCookie);
Dim MyCookieCollection as New HttpCookieCollection()
 Dim MyCookie As New HttpCookie("LastVisit")
 MyCookie.Value = DateTime.Now().ToString()
 MyCookieCollection.Add(MyCookie)

Kommentarer

Valfritt antal cookiesamlingar kan finnas i ett program, men endast samlingen som refereras av det inbyggda Cookies objektet skickas till klienten.

Metoden Add tillåter duplicerade cookies i cookiesamlingen. Använd metoden Set för att säkerställa att cookies är unika i cookiesamlingen.

Gäller för

Se även