HttpCookieCollection.GetKey Method (Int32)


Returns the key (name) of the cookie at the specified numerical index.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public string GetKey(
	int index


Type: System.Int32

The index of the key to retrieve from the collection.

Return Value

Type: System.String

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.

int loop1;

 HttpCookieCollection MyCookieCollection = Response.Cookies;

 for(loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
    if(MyCookieCollection.GetKey(loop1) == "LastVisit")
       MyCookieCollection[loop1].Value = DateTime.Now.ToString();

.NET Framework
Available since 1.1
Return to top