Response Object (Part 2 of 5): The collections
Part II of our tour of the handy Response object in the ASP Object Model explores the collections available for your use.
Original Author: Brad Hess from http://www.4aspdev.com
Alright we have covered all of the properties of the
Response Object so now lets look at the Collections.
The only collection in the response Object is the Cookies
Collection. This collection allows you to use the HTTP response header to
write cookies on the client machine. In an earlier example I used
thing can be done using the cookies collection. The cookies collection has
three properties: Item, Key and Count. To set the value of
a cookie you would do the following: Response.Cookie("Color") =
"Red". If you remember from the code example in the last
section a cookie can be what is called a dictionary cookie. In a
dictionary cookie each element can be referenced by name. I will go into
detail on how to set and use dictionary cookies later, but for now lets move on
to the attributes of the cookie. Each element of a cookie has the
following attributes associated with it: Domain, Expires, HasKeys,
Path, and Secure.
- The Domain allows you to set the domain that
the cookie is set to. This is a write-only property. Let's say
that you wanted to set a cookie that was sent to 4aspdev.com every time
someone requested a page in the 4aspdev.com domain. The code would
read: response.cookie("Color") = "4aspdev.com".
This cookie would get sent to 4aspdev.com every time the client requested a
page on that domain.
- The Expires attribute sets when the cookie
expires and is removed form the clients machine. If this value is not
set then the cookie is destroyed when the clients session ends. If the date
is set to before the current date the cookie will be destroyed when the
session ends. To use this attribute the code would read Response.Cookies("Color").Expires
= #1/31/2000#. (note the use of # around the date)
- The HasKeys attribute is used to determine if
the cookie is a dictionary cookie and if it has subkeys. I will go
into this more later.
- The Path attribute sets the path of the
virtual directory on the server where cookies are sent. Lets say we only
wanted cookies set to the /colors/personal virtual directory the code would
read response.cookies("Color") = "/colors/personal".
This sets it so that the cookie is only sent to this directory.
- The Secure property allows you to specify
whether the cookie is sent to the server only when the client is using
Secure Socket Layer. This is a true False value and is default to False To
set the value the code would read: response.Cookie("color").secure
No comments have been added for this post.
You must be logged in to make a comment.