Export (0) Print
Expand All

HttpCookie.HasKeys Property

Gets a value indicating whether a cookie has subkeys.

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

public bool HasKeys { get; }
/** @property */
public boolean get_HasKeys ()

public function get HasKeys () : boolean

Property Value

true if the cookie has subkeys, otherwise, false. The default value is false.

The following code example examines each member of a cookie collection for multiple values. If a cookie's HasKeys property is true, indicating that multiple values are present, this example copies the value names into one string array and the corresponding values into another string array. For an example of how to create multiple values for a cookie, see Values.

HttpCookieCollection MyCookieCollection = Request.Cookies;
 for(int loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
 {
    HttpCookie MyCookie = MyCookieCollection[loop1];

    if ( MyCookie.HasKeys )
    {
      NameValueCollection MyCookieValues =
          new NameValueCollection(MyCookie.Values);
      String[] MyKeyNames = MyCookieValues.AllKeys;
      foreach(string KeyName in MyKeyNames)
          {
              String[] MyValues = 
                  MyCookieValues.GetValues(KeyName);
          }
    }
 }


HttpCookieCollection myCookieCollection = get_Request().get_Cookies();

for (int loop1 = 0; loop1 < myCookieCollection.get_Count(); loop1++) {
    HttpCookie myCookie = myCookieCollection.get_Item(loop1);
    if (myCookie.get_HasKeys()) {
        NameValueCollection myCookieValues = new 
            NameValueCollection(myCookie.get_Values());
        String myValueNames[] = myCookieValues.get_AllKeys();
        String myValues[] = myCookieValues.get_AllKeys();
    }
}

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:
© 2014 Microsoft