This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
|
Bake in Persistent State with Cookies
William McLuskie |
If you're using Active Server Pages to serve up your Web site to users, you can easily use cookies to keep track of visitors. |
By design, HTTP is a stateless environment. The client browser requests individual documents from the Web server, which in turn receives the request, processes it, returns a document, and discards the request. HTTP does not provide any mechanism to associate a particular request with any previous one. With Active Server Pages (ASP), state can be maintained using session variables. Unfortunately, as their name implies, session variables are available only within the session or Web application in which they were created. Your Web application may appear as one logical application to the user, but it may actually be composed of several components, each in its own virtual directory. By using cookies, you can maintain application state across multiple Web applications.
Got Milk?
Which Flavor Would
You Like?
|
|
Dictionary cookies use an array metaphor of CookieName(Key) = CookieValue. |
|
Is That My Cookie?
|
Figure 1: Security Options in Internet Explorer 4.0 |
If you plan to use cookies in your application, you must ensure that your users have not disabled cookies in their browsers. This is a purely client-side decision. To enable cookies in Microsoft® Internet Explorer 4.x, select View | Internet Options and go to the Advanced tab. Scroll down to the Security section and select "Always accept cookies" (see Figure 1). If the user wants to see each cookie that the browser receives, they should select "Prompt before accepting cookies" in the Advanced tab and a Security Alert dialog will appear before a cookie is accepted (see Figure 2). Remember that you can have up to 130 cookies per pageand you'll have to click OK on that dialog after every one of them before your page is displayed. |
Figure 2: Cookie Security Alert |
Let's Bake a Batch
|
|
Allow Them to Cool Before Eating
Time to Clean Up
|
Figure 10: ASPSESSIONID Cookie Alert |
Conclusion
|
From the November 1998 issue of Microsoft Interactive Developer.