HttpCookieCollection.GetKey(Int32) 메서드

정의

지정된 숫자 인덱스에서 쿠키의 키(이름)를 반환합니다.

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

매개 변수

index
Int32

컬렉션에서 검색할 키의 인덱스입니다.

반품

로 지정된 index쿠키의 이름입니다.

예제

다음 예제에서는 쿠키 컬렉션에서 각 쿠키를 반환하고 이름이 "LastVisit"인지 확인하고, "LastVisit"이 발견되면 해당 값을 현재 날짜 및 시간으로 업데이트합니다.

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

적용 대상