![]() |
|
|
Cookies with KeysIn Cookies we worked with simple cookies
that only had one value associated with them. Cookies can also store
multiple values of related information. When this is the case they are
said to have Keys. Example 1: <% You can find the value of a cookie subkey by using the following syntax: syntax: Request.Cookies(NameofCookie)(NameofSubKey) So for our code in example 1 above we could use the code below to retrieve this cookie PersonalDetails with its 3 keys and write them out. <% The result would be: Remember that unless you set the Expires attribute, the cookie will only last as long as you have the browser open. You could set the Expires attribute as below in example 2. Example 2: <% Using the HasKeys Property We can use the HasKeys property to determine whether or not a cookie holds multiple values. Syntax: Request.Cookies(“theCookieName”).HasKeys Again if we wanted to determine whether our cookie PersonalDetails created in example 1 had keys we could run the code in example 3. Example 3: <% If the cookie named PersonalDetails has keys, then the variable BlnValue will be true otherwise the value will be false. Returning all the cookies and their valuesIf you wanted to check what cookies your server has sent to the user's computer you could run the code below. It checks for what cookies have been written and if they have keys.
<html>
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|