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

(Continued from previous part...)

Output:

Tests on the request object:
Total bytes = 0
QueryString.Count = 0
Form.Count = 0
ServerVariables.Count = 49
ALL_HTTP = HTTP_ACCEPT:*/* HTTP_ACCEPT_LANGUAGE:en-us HTTP_CONNECTION:...
ALL_RAW = Accept: */* Accept-Language: en-us Connection: Keep-Alive ...
APPL_MD_PATH = /LM/W3SVC/1/ROOT
APPL_PHYSICAL_PATH = c:\inetpub\wwwroot\
AUTH_PASSWORD = 
AUTH_TYPE = 
AUTH_USER = 
CERT_COOKIE = 
CERT_FLAGS = 
CERT_ISSUER = 
CERT_KEYSIZE = 
CERT_SECRETKEYSIZE = 
CERT_SERIALNUMBER = 
CERT_SERVER_ISSUER = 
CERT_SERVER_SUBJECT = 
CERT_SUBJECT = 
CONTENT_LENGTH = 0
CONTENT_TYPE = 
GATEWAY_INTERFACE = CGI/1.1
HTTPS = off
HTTPS_KEYSIZE = 
HTTPS_SECRETKEYSIZE = 
HTTPS_SERVER_ISSUER = 
HTTPS_SERVER_SUBJECT = 
INSTANCE_ID = 1
INSTANCE_META_PATH = /LM/W3SVC/1
LOCAL_ADDR = 127.0.0.1
LOGON_USER = 
PATH_INFO = /request_test.asp
PATH_TRANSLATED = c:\inetpub\wwwroot\request_test.asp
QUERY_STRING = 
REMOTE_ADDR = 127.0.0.1
REMOTE_HOST = 127.0.0.1
REMOTE_USER = 
REQUEST_METHOD = GET
SCRIPT_NAME = /request_test.asp
SERVER_NAME = localhost
SERVER_PORT = 80
SERVER_PORT_SECURE = 0
SERVER_PROTOCOL = HTTP/1.1
SERVER_SOFTWARE = Microsoft-IIS/5.0
URL = /request_test.asp
HTTP_ACCEPT = */*
HTTP_ACCEPT_LANGUAGE = en-us
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = localhost
HTTP_USER_AGENT = Mozilla/4.0 (compatible; MSIE 6.0; MSNIA; Windows NT...
HTTP_COOKIE = ASPSESSIONIDQQGQQVFQ=DFPLLCDACFFBCIBMCKALNNMK
HTTP_ACCEPT_ENCODING = gzip, deflate
Cookies.Count = 0
ClientCertificate.Count = 0

A couple of interesting things to note here:

  • The collection object can be interated by the "for each k in c" statement, where "k" is the key of each in the collection.
  • Since "c.Item(k)" is the default method, it can be written as "c(k)".
  • The ServerVariables object contains a lot of information, including remote host IP address, URL, translated path name, etc.

If you request this ASP page with the following url:

http://localhost/request_test.asp?Name=Bill+Smith&Country=Canada

You will see the following changes in the output:

Tests on the request object:
QueryString.Count = 2
Name = Bill Smith
Country = Canada
ServerVariables.Count = 49
...
QUERY_STRING = Name=Bill+Smith&Country=Canada

What happens here is:

  • When you request a Web page with a URL contains a "?", everything after "?" in the URL will be received by the server as the query string.
  • The query string will be store in the server variable called "QUERY_STRING". It will also be split into pairs of names and values and stored in "QueryString" collection.
  • "&" is used in the query string as delimiters.
  • Special characters in the query string need to be encoded. For example, " " is encoded as "+". I believe ASP offers both URL encoding and decoding methods.

The "response" Object

The "response" object is also a rich object. It contains all the information the server wants to send to the browser, and methods to manage that information:

  • Cookies: A collections of cookie objects the server wants to send to the browser.
  • Buffer: A boolean property indicating whether to buffer the page until the contents are completed.
  • Charset: A property representing the character set name in HTTP response header.
  • ContentType: A property representing the content type name in the HTTP reponse header.
  • Expires: A property representing the period of time before the page cached on a proxy server expires.
  • IsClientConnected: A boolean property indicating whether the browser has disconnected from the server.
  • Status: A property representing the status in the HTTP response header.
  • AddHeader name, value: A method to set or change the value of a variable in the HTTP response header.
  • AppendToLog(string): A method to append the specified string to the log file of the Web server.
  • BinaryWrite(data): A method to send binary data to the browser.
  • Clear(): A method to clear any buffered HTML output.
  • End(): A method to stop add data to the HTML output from both script statements and static HTML data.
  • Flush(): A method to sends buffered HTML output immediately to the browser.
  • Redirect(url): A method to redirect the browser to another URL.
  • Write(string): A method to write the specified string to the HTML output.

(Continued on next part...)

Part:   1  2  3 

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