HttpCookie.HasKeys Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a value indicating whether a cookie has subkeys.

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

public bool HasKeys { get; }

Property Value

Type: System.Boolean

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);
          }
    }
 }

.NET Framework
Available since 1.1
Return to top
Show: