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

ASP Objects

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

This chapter describes:

  • How ASP server presents the programming environment to ASP pages with a number of run-time objects.
  • Basic properties and methods of run-time objects: request, response, server, application, and session.

ASP Object Model

ASP enabled Web server provides a number run-time objects as part of the server side scripting environment:

  • Request: An object holding information the client sends to the server as an HTTP request.
  • Response: An object holding information the server sends to the client as an HTTP response.
  • Server: An object holding information common to running virtual directories.
  • Application: An object holding information common to all running HTTP sessions under a single virtual Web directory.
  • Session: An object representing a sequence of HTTP requests and responses from one client system.

The following diagram illustrates the relations among the ASP objects:

Server
 |- Application X
 |   |- Session A            Client A
 |   |   |- Request #1  <---  |
 |   |   |- Response #1 --->  |
 |   |   |- Request #2  <---  |
 |   |   |- Response #2 --->  |
 |   |   |- ......            |
 |   |
 |   |- Session B            Client B
 |   |   |- Request #1  <---  |
 |   |   |- Response #1 --->  |
 |   |   |- Request #2  <---  |
 |   |   |- Response #2 --->  |
 |   |   |- ......            |
 |   |- ......
 |
 |- Application Y
 |- ......

The "request" Object

The request object is a very rich object. It contains everything the client sends to the server:

  • QueryString: A read only collection object representing all the names and values sent from the browser by the GET method.
  • Form: A read only collection object representing all names and values sent from the browser by the POST method.
  • Cookies: A read only collection object representing all the cookies sent from the browser.
  • ServerVariables: A read only collection object representing all the names and values in the HTTP request header and in the server environment.
  • TotalBytes: A read only property indicating the total number of bytes in this request.
  • BinaryRead(): A method to read all names and values sent from the browser by the POST method.

The following ASP page shows how to access the property and collections of the request object.

<script language="vbscript" runat="server">
'  request_test.asp
'  Copyright (c) 2002 by Dr. Herong Yang
'  This program shows how to use the "request" object.
'
   response.write("<html><body>")
   response.write("<b>Tests on the request object</b>:<br/>")
   response.write("Total bytes = " & request.TotalBytes & "<br/>")
   set c = request.QueryString
   response.write("QueryString.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c.Item(v) & "<br/>")
   next
   set c = request.Form
   response.write("Form.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c.Item(v) & "<br/>")
   next
   set c = request.ServerVariables
   response.write("ServerVariables.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c(v) & "<br/>")
   next
   set c = request.Cookies
   response.write("Cookies.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c(v) & "<br/>")
   next
   set c = request.ClientCertificate
   response.write("ClientCertificate.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c(v) & "<br/>")
   next
   response.write("</body></html>")
</script>

(Continued on next part...)

Part:   1  2  3 

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