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...)

The following ASP page gives you an idea how to use the response object and its buffer mechanism.

<script language="vbscript" runat="server">
'  response_buffer_test.asp
'  Copyright (c) 2002 by Dr. Herong Yang
'  This program shows how to use the buffer in the response object
'
   response.write("<html><body>")
   response.write("<b>Tests on the response object</b>:</br>")
   response.Buffer = true
   response.write("Text line 1.<br/>")
   response.Clear()
   response.write("Text line 2.<br/>")
   response.End()
   response.write("Text line 3.<br/>")
   response.write("</body></html>")   
</script>

Output:

Text line 2.

As you can see from the output, the first text line was cleared out from the response buffer by the call to Clear(). The call to End() stopped the Web server to put any more text to the output. This was why the output only had the second text line.

The "server" Object

Server: An object provided by the server to hold information and methods common to all running virtual directories.

  • ScriptTimeout: A property to set the maximum time allowed for an ASP page to run.
  • CreateObject(class): A method to instantiate object out of the specified class.
  • HTMLEncode(string): A method to apply HTML encoding to the specified string.
  • URLEncode(string): A method to apply URL encoding to the specified string.
  • MapPath(path_name): A method to map URL path name to the file system path name on the Web server system.

The "application" Object

application: An object provided by the server to hold information and methods common to all sessions related to one virtual directory.

  • Contents: A collection object acting an cache for ASP pages from different sessions to share information. Since "Contents" is the default collection, we write 'application.Contents("myVar")' as 'application("myVar")'.
  • Lock(): A method to lock the application object for synchronization.
  • UnLock(): A method to unlock the application object for synchronization.
  • OnStart(): An event handler to be called when the first HTTP request comes to this virtual directory.
  • OnEnd(): An event handler to be called the server wants to terminate the service on this virtual directory.
  • 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.

The "session" Object

session: An object provided by the server to hold information and methods common to all ASP pages running under one session.

  • Contents: A collection object acting an cache for different ASP pages to share information. Since "Contents" is the default collection, we write 'session.Contents("myVar")' as 'session("myVar")'.
  • Abandon(): A method to destroy the current session.
  • SessionID: A read only property to return the id of the current session.
  • TimeOut: A property to set timeout period on this session.
  • OnStart(): An event handler to be called when the first HTTP request comes from a new user.
  • OnEnd(): An event handler to be called the session is abandoned or timed out.

Here is a simple ASP page shows you the session object, session_test.asp:

<script language="vbscript" runat="server">
'  session_test.asp
'  Copyright (c) 2002 by Dr. Herong Yang
   session("PATH_INFO") = request.ServerVariables("PATH_INFO")
   response.write("<html><body>")
   response.write("<b>Tests on the session object</b>:<br/>")
   response.write("session.SessionID = " & session.SessionID & "<br/>")
   set c = session.Contents
   response.write("session.Contents.Count = " & c.Count & "<br/>")
   for each v in c
      response.write( v & " = " & c.Item(v) & "<br/>")
   next
   response.write("</body></html>")   
</script>

Output:

Tests on the session object:
session.SessionID = 1018427069
session.Contents.Count = 1
PATH_INFO = /session_test.asp

Note that session.Contents is empty intially. I added the "PATH_INFO" of the current request to it to show you how add and retreive a parameter from session.Contents.

Part:   1  2  3 

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