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