HttpCookie.HasKeys Property

Definition

Gets a value indicating whether a cookie has subkeys.

public bool HasKeys { get; }

Property Value

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

Examples

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

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also