Another important function of Response object is the output of HTTP headers to
the client. As part of the HTTP header, these types of response objects should
be sent before sending any body content to the client.
Response.Cookies Collection
Response.Cookies collection adds or sets the value of a cookie. The specified
cookie will be created, if the cookie does not exist. Or the value of specified
cookie will be set.
The parameter "cookie" is the
name of cookie. The data type of
"cookie" is string and is enclosed by quotation marks (" "). .
key
The parameter "key" is the
optional key of the parameter "cookie". If the "key" is specifed, "cookie" is a
dictionary and the key is set to "value" The data type of
"key" is string and is enclosed by quotation marks (" "). .
attribute
The parameter "attribute" is the
optional information of the parameter "cookie" with delimeter ".". The possible
values of attribute are.
attribute value
Description
Domain
Write-only. To specify the cookie is sent only to requests to the specified
domain
Expires
Write-only. To specify the date on which the cookie expires so that the cookie
may be stored by the client in the client's disk after the session ends.
Otherwise the cookie expires when the session end or if the date of "Expires"
attribute setting is before the current date.
HasKeys
Read-only. To specify whether the cookie contains keys.
Path
Write-only. To specify the cookie is sent only to requests to the specified
path. If the "Path" attribute is not set, the default value is the application
path.
Secure
Write-only. To specify whether the cookie is secure or not.
Value
The parameter "Value" is the
value assign to the "cookie", "key" or "attribute". The data type of
"Value" is string and is enclosed by quotation marks (" ").
Remarks:
Cookies are transmitted as clear text in the HTTP header. Cookies are not
suitable to store important data, such as login name and passwords. Besides,
Cookies collection are only strings contained in an request headers. The values
of Cookies collection can also be generated by any user. Therefore Cookie data
in the HTTP header is not a secure way to identify a user.
If the same cookie name is reassigned in the same response, the later one will
destroy the previous one. That is old value will be replaced by new value for
the same cookie. And a cookie with key will be destroyed by a cookie without key
or a cookie without key will be destroyed by a cookie with key.
Examples:
Default value with No Response.Cookies
ASP script command:
<% %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: private
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1 Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: cookiename=key2=cvalue2&key1=cvalue1; path=/
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: private
Response.Cookies
with "cookiename and (key1 = cookievalue1 and key2 =
cookievalue2)" and then set cookie "ckey" =
Response.Cookies("cookiename").HasKeys