Search Tools Links Login

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

Code

Part 1,2,3,4,5


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
JavaScript to write a cookie value to the clients machine.?á The exact same
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
    = True
    .


About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 112 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.