Response Object (Part 2 of 5): The collections

Submitted on: 1/5/2015 7:15:00 AM
By: Brad Hess from (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 4036
     Part II of our tour of the handy Response object in the ASP Object Model explores the collections available for your use.

				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 every time someone requested a page in the domain. The code would read: response.cookie("Color") = "". This cookie would get sent to 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.

Other 3 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.