|
||
|
Lesson 7
Objective
|
Request.Cookies
Read user data written during a prior visit. |
|
|
HTTP is known as a "stateless" protocol.
After a browser and server have completed an HTTP transaction, no information (such as data submitted through an HTML Form) is retained. This loss of user information occurs when the user moves from page to page in a Web site and when a user leaves one Web site for another. Cookies were developed as a way to retain user data between Web pages or visits to a Web site.
A cookie consists of one or more name-value pairs sent to a browser from a Web server. The browser stores these cookies in a text file (called cookie.txt). Although you cannot store much information in any one cookie, they are still useful for:
In this lesson, we explain retrieving cookie values that were set prior to our reading them. Setting initial or updated cookie values uses the ASP Response object, which will be described in an upcoming lesson. Reading a T-shirt cookie
On our course project T-shirt store Web site, we could use a cookie to store the preferred T-shirt size for a customer to avoid
requesting this same information each time the user visits the site. Once the cookie, called "ShirtSize", had been
created, we could read the cookie's contents and write the value (for example, XL) to the user's browser with this
code segment:
<TD>Preferred size:</TD>
<TD><%= Request.Cookies("ShirtSize") %></TD>
Preferred size: XXL |
||
|
|
||
