")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "="& Request.Cookies(x)(y))
response.write("<br /")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "
")
end if
response.write "
Coll Cookies Response
* * Complete Response Object Reference Manual](#)
* * *
The Cookies collection is used to set or get the value of a cookie. If the cookie does not exist, it is created and assigned the specified value.
**Note:** The Response.Cookies command must be placed before the tag.
## Syntax
Response.Cookies(name)[(key)|.attribute]=value
variablename=Request.Cookies(name)[(key)|.attribute]
| Parameter | Description |
| --- | --- |
| name | Required. The name of the cookie. |
| value | Required (for the Response.Cookies command). The value of the cookie. |
| attribute | Optional. Specifies information about the cookie. Can be one of the following parameters: * Domain - Write-only. The cookie is sent only to requests that reach this domain. * Expires - Write-only. The expiration date of the cookie. If no date is specified, the cookie will expire when the session ends. * HasKeys - Read-only. Specifies whether the cookie has keys (this is the only attribute that can be used with the Request.Cookies command). * Path - Write-only. If set, the cookie is sent only to requests that reach this path. If not set, the application's path is used. * Secure - Write-only. Indicates whether the cookie is secure. |
| key | Optional. Specifies the key where the value is assigned. |
* * *
## Examples
The "Response.Cookies" command is used to create a cookie or set the value of a cookie:
In the code above, we created a cookie named "firstname" and assigned it the value "Alex".
You can also set attributes for a cookie, such as setting the expiration date:
Now, the cookie named "firstname" has the value "Alex" and its expiration date on the user's computer is May 10, 2002.
The "Request.Cookies" command is used to retrieve the value of a cookie.
In the following example, we retrieve the value of the cookie "firstname" and display it on the page:
Output:
Firstname=Alex
A cookie can contain a collection of multiple values. We call this a cookie having keys.
In the following example, we will create a cookie collection named "user". The "user" cookie has keys containing information about the user:
The following code reads all the cookies that the server has sent to the user. Note that we use the HasKeys attribute to determine if a cookie has keys:
<%
dim x,y
for each x in Request.Cookies
response.write("
YouTip