System.Web Namespace HttpCookieCollection Class
Returns the key ( name ) of the cookie at the specified numerical index.
[ VB ]
Public Function GetKey ( _
ByVal index As Integer _
) As String
[ C# ]
public string GetKey (
int index
);
[ C++ ]
public: String* GetKey (
int index
);
[ JScript ]
public function GetKey (
index : int
) : String;
- index
- The index of the key to retrieve from the collection.
The name of the cookie specified by index.
The following example returns each cookie from the cookie collection, checks whether it is named "LastVisit", and, If "LastVisit" is found, updates its value to the current date and time.
[ VB ]
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
[ C# ]
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 ] );
}
}
HttpCookieCollection Members