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

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

반환

String

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

적용 대상