asp.net.ph

HttpCookieCollection.GetKey Method

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;

Parameters

index
The index of the key to retrieve from the collection.

Return Value

The name of the cookie specified by index.

Example

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 ] );
  }
}
See Also

HttpCookieCollection Members Skip Navigation Links


Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note