The manual Page
Version française
     Collection Request.Cookies  
[ index | glossary | news | downloads | links ]
 
  introduction to ASP
writting in ASP
ASP variables
the ASP 3.0 objects
the object Request
   .TotalBytes
   .ClientCertificate
   .Cookies
   .Form
   .QueryString
   .ServerVariables
   .BinaryRead
the object Response
   .Status
   .Cookies
   .AddHeader
   .AppendToLog
   .BinaryWrite
   .Clear
   .End
   .Flush
   .Redirect
   .Write
 
news
glossary
downloads
 
guest book
credits
contact
 
 
research
 
last update
25/03/2002
Valid HTML 4.0!
Valid CSS!
Hit-Parade
Measure your audience

Synopsis

Request.Cookies(Name)[(Key)|.Attribute]

Read only

This collection gives access to the cookies sent by the client to the server. This collection cannot be used to create or set cookies; to set cookies, one must use the collection Cookies of the object Response instead.

The name is mandatory.

Reminder about the cookies

A cookie is a piece of information (a login, a session ID...) the client and the server exchange within the headers of an HTTP message. This piece of information is actually only useful to the server, even if the client holds it (in memory, or in a specific file on a hard drive). A cookie the server sends to a client cannot but be used by this server. This allows customization of cookies and the safe keeping of confidential data.

Since it does not store the cookies it sends from one page to another, a Web server cannot but use a cookie if and only if the client sends it back. Therefore, a client would send the cookies it holds in every HTTP request it makes to the server. This is why in ASP, we access (read) the cookies thanks to the object Request. In parallel, the cookies are created, set and sent to the client thanks to the object Response.

For further details about cookies, see the HTTP section.

Us of the collection Request.Cookies

Cookies' names

Every cookie has a name (exactly like variables). Therefore, to read the value of a cookie, we use its name:

If a cookie called foo was created and set in a previous ASP page, we would access it like this:

Response.Write("The value of the cookie foo is " & Request.Cookies("foo"))

The keys and the attribute HasKeys

We can use the cookies as dictionaries (associative arrays); keys are then used to access to the different elements:

Let's suppose the "cookie-dictionary" foo contains the following 2 elements bar1 and bar2. We use these elements like this:

Request.Cookies("foo")("bar1")
Request.Cookies("foo")("bar2")

To know if a cookie has keys (i.e. to know if it is a dictionary), we use the only attribute of the collection: HasKeys:

' Does the cookie foo have keys?
' If so, what are they?
If Cookies("foo").HasKeys Then
	Response.Write("There are keys:<BR>")
	For Each key In Cookies("foo").Keys
		Response.Write(key & "<BR>")
	Next
Else
	Response.Write("No key")
End If

printable format printable format



Copyright © 2000-2002 themanualpage.org - This site is submissive to the terms of the GNU GPL and FDL licences.