HttpCookieCollection.GetKey(Int32) Metod

Definition

Returnerar cookiens nyckel (namn) vid det angivna numeriska indexet.

public:
 System::String ^ GetKey(int index);
public string GetKey(int index);
member this.GetKey : int -> string
Public Function GetKey (index As Integer) As String

Parametrar

index
Int32

Indexet för nyckeln som ska hämtas från samlingen.

Returer

Namnet på cookien som anges av index.

Exempel

I följande exempel returneras varje cookie från cookiesamlingen, kontrollerar om den heter "LastVisit" och uppdaterar värdet till aktuellt datum och tid om "LastVisit" hittas.

int loop1;

 HttpCookieCollection MyCookieCollection = Response.Cookies;

 for(loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
 {
    if(MyCookieCollection.GetKey(loop1) == "LastVisit")
    {
       MyCookieCollection[loop1].Value = DateTime.Now.ToString();
       MyCookieCollection.Set(MyCookieCollection[loop1]);
    }
 }
Dim loop1 As Integer
 Dim MyCookie As HttpCookie
 Dim MyCookieCollection As HttpCookieCollection = Request.Cookies
 
 For loop1 = 0 To MyCookieCollection.Count - 1
    If MyCookieCollection.GetKey(loop1) = "LastVisit" Then
       MyCookieCollection(loop1).Value = DateTime.Now().ToString()
       MyCookieCollection.Set(MyCookieCollection(loop1))
       Exit For
    End If
 Next loop1

Gäller för