The ASP (Active Server Pages) Object Model
By Stephen Bucaro
ASP (Active Server Pages) is a server-side scripting engine first released in December 1996
as part of Microsoft's IIS (Internet Information Services). It allows dynamically generated
web pages. After ASP.NET was released in January 2002, ASP became known as Classic ASP.
Microsoft has promised to support Classic ASP until at least October 14, 2025.
As a server-side scripting engine, the ASP interpreter can run scripts written in VBScript,
JScript and PerlScript. The interpreter reads and executes script code between the <% and
%> tags. The default language is VBScript, but placing the the <%@ language="JScript"%>
directive at the top of the page can be used to select a different language.
ASP runs only on Windows. Web pages that use ASP must have the .asp filename extension. The
ASP Architecture consists of six built-in objects: Application, Session, Request, Response,
ASPError, and Server.
The Application object stores global variables. Shown below is example code for
storing the string "cart" in a global variable named "apName" in the Application object.
<%
Application("apName") = "cart"
%>
The Session object stores variables related to only to a single visitor. Shown below
is example code for storing the string named "name" in a session variable named "apVisitor" in
the Session object.
<%
Session("apVisitor") = "name"
%>
The Request object is used to read that was sent by the client's browser: Form,
Querystring, or HTTP Cookie. Shown below is example code for reading data sent by the GET method.
<%
name = Request.QueryString("name")
%>
Request.Form reads data sent by POST.
The Response object is used to send information to the client's browser, such as the
writing of the text on a page or HTTP Cookie. Shown below is example code for writing the text
"Welcome" to the clients browser.
<%
Response.Write "Welcome"
%>
The Err object can be used for the management of errors. Shown below is example code for
writing the details of the error to the clients browser.
<%
On Error Resume Next
If Err.Number <> 0 Then
Response.Write "Error Number: " & Server.HTMLEncode(Err.Number)
Response.Write " Error Source: " & Server.HTMLEncode(Err.Source)
Response.Write " Error Description: " & Server.HTMLEncode(Err.Description)
Err.Clear
End If
%>
The Server object can be used to create instances of components installed on the server.
Shown below is example code of the server object creating a FileSystemObject object. The
FileSystemObject object can be used to manipulate files, folders, and directory paths.
The example code shown below creates a text file and then writes some text to the file
<%
dim fsObj, fname
set fsObj = Server.CreateObject("Scripting.FileSystemObject")
set fname = fsObj.CreateTextFile("test.txt", true)
fname.WriteLine("Hello World")
fname.Close
set fname = nothing
set fsObj = nothing
%>
The Server object can also be used to create connections to a database (ADO) and manipulation
of the database.
|