HttpCookieCollection.GetKey Method

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
)
public String GetKey (
	int index
)
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.

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.

No code example is currently available or this language may not be supported.
int loop1;
HttpCookieCollection myCookieCollection = get_Response().get_Cookies();

for (loop1 = 0; loop1 < myCookieCollection.get_Count(); loop1++) {
    if (myCookieCollection.GetKey(loop1).equals("LastVisit")) {
        myCookieCollection.get_Item(loop1).set_Value(
            DateTime.get_Now().ToString());
        myCookieCollection.Set(myCookieCollection.get_Item(loop1));
    }
}

var myCookie : HttpCookie
var myCookieCollection : HttpCookieCollection = Request.Cookies

for(var i= 0; i < myCookieCollection.Count; i++){
  if(myCookieCollection.GetKey(i) == "LastVisit"){
      myCookieCollection(i).Value = DateTime.Now.ToString()
      myCookieCollection.Set(myCookieCollection(i))
      break
  }
}
  

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: