Uredi

Deli z drugimi prek


HttpCookie.HasKeys Property

Definition

Gets a value indicating whether a cookie has subkeys.

public:
 property bool HasKeys { bool get(); };
public bool HasKeys { get; }
member this.HasKeys : bool
Public ReadOnly Property HasKeys As Boolean

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

Dim MyCookieCollection As HttpCookieCollection
Dim MyCookie As HttpCookie
Dim MyKeyNames() As String
Dim MyValues() As String
Dim loop1 As Integer

MyCookieCollection = Request.Cookies
For loop1 = 0 To MyCookieCollection.Count - 1
    MyCookie = MyCookieCollection(loop1)
    If MyCookie.HasKeys Then
        Dim MyCookieValues As NameValueCollection = _
            New NameValueCollection(MyCookie.Values)
        MyKeyNames = MyCookieValues.AllKeys
        For Each KeyName As String In MyKeyNames
            MyValues = MyCookieValues.GetValues(KeyName)
        Next
    End If
Next loop1

Applies to

See also