Export (0) Print
Expand All

HttpCookie.HasKeys Property

Gets a value indicating whether a cookie has subkeys.

[Visual Basic]
Public ReadOnly Property HasKeys As Boolean
[C#]
public bool HasKeys {get;}
[C++]
public: __property bool get_HasKeys();
[JScript]
public function get HasKeys() : Boolean;

Property Value

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

Example

The following example examines each member of a cookie collection for multiple values and If multiple values are present (HasKeys = true), 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.

[Visual Basic] 
Dim MyCookieCollection As HttpCookieCollection
 Dim MyCookie As HttpCookie
 Dim MyValueNames() 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)
       MyValueNames = MyCookieValues.AllKeys
       MyValues = MyCookieValues.AllKeys
    End If
 Next loop1
    

[C#] 
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[] MyValueNames = MyCookieValues.AllKeys;
       String[] MyValues = MyCookieValues.AllKeys;
    }
 }
    

[C++] 
HttpCookieCollection* MyCookieCollection = Request->Cookies;
 for(int loop1 = 0; loop1 < MyCookieCollection->Count; loop1++)
 {
    HttpCookie* MyCookie = MyCookieCollection->Item[loop1];

    if ( MyCookie->HasKeys )
    {
       NameValueCollection* MyCookieValues = 
          new NameValueCollection(MyCookie->Values);
       String* MyValueNames[] = MyCookieValues->AllKeys;
       String* MyValues[] = MyCookieValues->AllKeys;
    }
 }
    

[JScript] 
var myCookieCollection : HttpCookieCollection
var myCookie : HttpCookie
var myValueNames : String[]
var myValues : String[]

myCookieCollection = Request.Cookies
for(var loop1 = 0; loop1 < myCookieCollection.Count; loop1++){
  myCookie = myCookieCollection[loop1]
  if(myCookie.HasKeys){
    var myCookieValues : NameValueCollection = new NameValueCollection(myCookie.Values)
    myValueNames = myCookieValues.AllKeys
    myValues = myCookieValues.AllKeys
  }
}
    

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpCookie Class | HttpCookie Members | System.Web Namespace

Show:
© 2014 Microsoft