Bagikan melalui


HttpCookie.HasKeys Properti

Definisi

Mendapatkan nilai yang menunjukkan apakah cookie memiliki subkuncu.

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

Nilai Properti

true jika cookie memiliki subkunjuk, jika tidak, false. Nilai defaultnya adalah false.

Contoh

Contoh kode berikut memeriksa setiap anggota koleksi cookie untuk beberapa nilai. Jika properti cookie HasKeys adalah true, menunjukkan bahwa beberapa nilai ada, contoh ini menyalin nama nilai ke dalam satu array string dan nilai yang sesuai ke dalam array string lain. Untuk contoh cara membuat beberapa nilai untuk cookie, lihat 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

Berlaku untuk

Lihat juga