HttpCookieCollection.GetKey(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳 cookie 的金鑰(名稱)在指定的數值索引。
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
從集合中擷取的金鑰索引。
傳回
由 所指定的 indexcookie 名稱。
範例
以下範例會回傳 Cookie 集合中的每個 Cookie,檢查其名稱是否為「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