ASP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.11

Using Cookies

Part:   1  2  3 

ASP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

hyBook - Guestbook Application

Using MS Access Databases

ActiveX Data Object (ADO)

Controlling Response Header Lines

Microsoft Scripting Runtime DLL

Using Cookies

ASP Sessions

ASP Objects

Microsoft Script Debugger

Internet Information Services (IIS)

... Table of Contents

(Continued from previous part...)

Cookie%5Fp%5F3
Cookie%5Fc%5F2%5F4=Value%5Fc%5F2%5F4&Cookie%5Fc%5F1%5F3=Value%5Fc%5F1%5F3
localhost/
1024
1584531456
31520289
2345072944
29563936
*
Cookie%5F1
Value%5F1
localhost/
1024
1584531456
31520289
2345672944
29563936
*

If you click the IE refresh button, you will get the following in the IE window:

Cookies received at this time::
Cookies.Count = 2
Cookie_p_3 = Cookie%5Fc%5F1%5F3=Value%5Fc%5F1%5F3&Cookie%5Fc%5F2%5F4=V...
Cookie_p_3.Item(Cookie_c_1_3) = Value_c_1_3
Cookie_p_3.Item(Cookie_c_2_4) = Value_c_2_4
Cookie_1 = Value_1
Adding a persistent cookie:
Cookie_3 = Value_3
Adding a persistent cookie with domain:
Cookie_d_4 = Value_d_4
Adding a persistent cookie with keys:
Cookie_p_5.Item(Cookie_c_1_5) = Value_c_1_5
Cookie_p_5.Item(Cookie_c_2_6) = Value_c_2_6

To prove that the cookies are really persisted, close your IE browser. And run it again to request the same ASP page, special_cookies.asp, you will get:

Cookies received at this time::
Cookies.Count = 4
Cookie_p_3 = Cookie%5Fc%5F1%5F3=Value%5Fc%5F1%5F3&Cookie%5Fc%5F2%5F4=V...
Cookie_p_3.Item(Cookie_c_1_3) = Value_c_1_3
Cookie_p_3.Item(Cookie_c_2_4) = Value_c_2_4
Cookie_p_5 = Cookie%5Fc%5F1%5F5=Value%5Fc%5F1%5F5&Cookie%5Fc%5F2%5F6=V...
Cookie_p_5.Item(Cookie_c_1_5) = Value_c_1_5
Cookie_p_5.Item(Cookie_c_2_6) = Value_c_2_6
Cookie_1 = Value_1
Cookie_3 = Value_3
Adding a persistent cookie:
Cookie_5 = Value_5
Adding a persistent cookie with domain:
Cookie_d_6 = Value_d_6
Adding a persistent cookie with children:
Cookie_p_7.Item(Cookie_c_1_7) = Value_c_1_7
Cookie_p_7.Item(Cookie_c_2_8) = Value_c_2_8

From this tutorial, we have learned:

  • Cookies will be persisted into a file, if you set the expiration date.
  • Cookie expiration dates must be within Jan 1, 1980 and Jan 19, 2038. This is weird.
  • This cookie file is not so easy to read. But you can still figure out some information. Of course, "%5F" represents "_".
  • Cookie names can not have space characters.
  • The default domain of a cookie is the domain from where it come from. In our tutorial, all cookies are come from localhose/, so they all have this domain name, when persisted into the cookie file.
  • My statement 'response.cookies(n).domain = "localhost/"' is not working. Cookies defined with this statement were ignored by the IE browser.
  • IE browser only takes 20 cookies from one Web server.
  • IE browser can only support up to 300 cookies.
  • Each cookie is limited to 4 KB in size.
  • The cookie(n).Item(k) method is the default method, so it can be simplified as cookie(n)(k).
  • Cookies with itemized values are just regular cookie with a special value format of "key=value&key=value...".

Some Other Cookie Definitions

A persistent cookie is one stored as a file on your computer, and it remains there when you close Internet Explorer. The cookie can be read by the Web site that created it when you visit that site again.

A temporary or session cookie is stored only for your current browsing session, and is deleted from your computer when you close Internet Explorer.

A first-party cookie either originates on or is sent to the Web site you are currently viewing. These cookies are commonly used to store information, such as your preferences when visiting that site.

A third-party cookie either originates on or is sent to a Web site different from the one you are currently viewing. Third-party Web sites usually provide some content on the Web site you are viewing. For example, many sites use advertising from third-party Web sites and those third-party Web sites may use cookies. A common use for this type of cookie is to track your Web page use for advertising or other marketing purposes. Third-party cookies can either be persistent or temporary.

Part:   1  2  3 

Dr. Herong Yang, updated in 2002
ASP Tutorials - Herong's Tutorial Notes - Using Cookies