Cookie Properties and Itemized Values

This section provides a tutorial example on how to manage cookie properties and itemized values using the cookie collection object provided in the ASP programming interface.

The cookie collection actually stores cookie objects, not just a named value. I don't have a full description of the cookie object (class), but I know a number properties of the cookie object.

Here is an ASP page to illustrate these special features:

<script language="vbscript" runat="server">
'  special_cookies.asp
'  Copyright (c) 2002 by Dr. Herong Yang
'  This ASP page sends and receives some special cookies.
'
   response.write("<html><body>")
   ' Displaying all the cookies 
   response.write("<b>Cookies received at this time:</b>:<br/>")
   set c = request.Cookies
   response.write("Cookies.Count = " & c.Count & "<br/>")
   for each n in c
      response.write(n & " = " & c(n) & "<br/>")
      if c(n).hasKeys then
      	 for each k in c(n)
            response.write(n&".Item("&k&") = " & c(n).Item(k) & "<br/>")
         next
      end if
   next
   response.write("<b>Adding a persistent cookie:</b><br/>")
   n = "Cookie_" & (c.Count+1)
   v = "Value_" & (c.Count+1)
   response.write( n & " = " & v & "<br/>")
   response.cookies(n) = v
   response.cookies(n).expires = #12/31/2029 00:00:00#
   response.write("<b>Adding a persistent cookie with domain:</b><br/>")
   n = "Cookie_d_" & (c.Count+1)
   v = "Value_d_" & (c.Count+1)
   response.write(n & " = " & v & "<br/>")
   response.cookies(n) = v
   response.cookies(n).expires = #12/31/2029 00:00:00#
   response.cookies(n).domain = "localhost/"
   response.write("<b>Adding a persistent cookie with keys:</b><br/>")
   n = "Cookie_p_" & (c.Count+1)
   k = "Cookie_c_1_" & (c.Count+1)
   v = "Value_c_1_" & (c.Count+1)
   response.write(n& ".Item("&k&") = " & v & "<br/>")
   response.cookies(n).Item(k) = v
   k = "Cookie_c_2_" & (c.Count+1)
   v = "Value_c_2_" & (c.Count+1)
   response.write(n&".Item("&k&") = " & v & "<br/>")
   response.cookies(n)(k) = v
   response.cookies(n).expires = #12/31/2029 00:00:00#
   response.write("</body></html>")
</script>

Last update: 2002.

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

 ASP Session

Creating and Managing Cookies

 What Is a Cookie?

 Sending and Receiving Cookies

Cookie Properties and Itemized Values

 Cookie Test Program Result

 Special Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 PDF Printing Version