Help > Web Development > Reference > Scripting Objects > Response Object > Cookies Collection

Response.Cookies Collection

The cookies collection enables you set or clear cookies in the HTTP response.

Cookies are small amounts of information that are sent around with each HTTP request to the server.  A cookie allows you to keep some state information about the user that is re-transmitted each time the user accesses the website.  Note that cookies are sent in clear-text and should not be used to store password or any other sensitive data.

Properties
Count Returns the number of cookies sent this this request.
Item(name or index) Returns the cookie with the given name or index.
Key(index) Returns the name of the cookie at the given index.

Methods
Add(name) Adds a new cookie with the given name.

Cookie Object

The cookie object represents a single cookie in the HTTP response.  A single cookie can include one or more values, as long as the total length does not exceed 250 characters.

Properties

Count Returns the number of cookies sent this this request.
HasKeys Returns boolean value indicating if the current cookie has more than one value, i.e. it uses name/value pairs.
Item(empty or name or index) Gets or returns the cookie with the given name or index.
Key(index) Gets or returns the name of the cookie at the given index.
Domain Gets or returns the domain restriction for this cookie.  The cookie will only be delivered to requests with the specified domain.
Expires Gets or returns the date/time when the cookie is to expire.
Path Gets or returns the path restriction for this cookie.  The cookie will only be delivered to requests with the specified path.
Remarks

Perceptive Enterprise Search supports multiple keyed or single keyed cookies.  To generate a multi-keyed cookie, use the following:

<%
Response.Cookies("cookieA")("firstname") = "john"
Response.Cookies("cookieA")("lastname") = "smith"
%>

the following HTTP header will be added to the response:

Set-Cookie: cookieA=firstname=john&lastname=smith

To create a single valued cookie, use the following:

<% Response.Cookies("cookieB") = "Cookie Value" %>
this will result in the following HTTP header being added to the response:

Set-Cookie: cookieB=Cookie+Value
To force a cookie to expire on a given date:
<% 
Response.Cookies("cookieB") = "Cookie Value"
Response.Cookies("cookieB").Expires = DateAdd("m", 1, Now)
%>
will result in the following HTTP header being added to the response: 
Set-Cookie: cookieB=Cookie+Value; expires=Tuesday, 1 Jun 2006 12:00:00 GMT
Applies To
Response Object