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
要從集合中擷取的索引鍵的索引。
傳回
index
所指定的 Cookie 名稱。
範例
下列範例會從 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