HttpCookie.HasKeys Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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);
}
}
}
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
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: