Active Server Pages Object Model
Active Server Pages Object Model
REQUEST OBJECT
1
WEB TECHNOLGY 200
9
Request object handles all of the requests from the user, including data
from cookies, forms and security certificates. This object is used when
getting information from the user.
An overview of Request Object
Collections Events Methods Properties
Client Certificate Binary Read Total Bytes
Cookies
Form
Query String
Server Variable
Cookies: cookies are small files of clear text that contain information such
as user preferences when changing pages within a site or for subsequent
visits.
Servervariables
Syntax:
1
WEB TECHNOLGY 200
9
1
WEB TECHNOLGY 200
9
RESPONSE OBJECT
Response Object handles the task of sending data back to the user. The
Response Object’s write method can be used explicitly and implicitly. The
Response Object’s Is Client Connected property checks to see if the
connection between the user or client is still alive, which relies on the
session object behind the scenes.
An overview of Response Object
2
WEB TECHNOLGY 200
9
Syntax:
201 Created
202 Accepted
204 No Content
401 Unauthorized
403 Forbidden
404 NA Found
501
1. response.write Not Implemented
3. response.redirect=URL
503 Service Unavailable
4. response.addheader(“header name”,”header
value”)
Syntax for methods of response object:
5. response.appendtolog(string)
6. <%response.clear%>
1
7. <%response.end%>
8. <%response.flush%>
WEB TECHNOLGY 200
9
The user can set for the user’s browser to cache the page. If it is to
be cached, how long? The web pages should be cached on the
client’s machine, the response object is provided with two properties.
They are:
– Expires
– Expires Absolute
Expires
Using this property we can specify for how long? The client’s
machine should cache the current page in terms of minutes.
Syntax:
<%response.expires=time in
minutes%>
Expires Absolute
If we want a particular page to be removed from the client’s machine
on a particular date and time, we can use the Expires Absolute
property of the Response Object.
Syntax:
<%response.expiresabsolute=#date,
2
time#%>
WEB TECHNOLGY 200
9
<
%response.isclientconnecte
Clear
When clear method is invoked the response body of the http is erased
Syntax:
<
%response.clear
End
The End method causes the server to stop the execution the script and
send any buffered output.
Syntax:
<%response.end
%>
Flush
2
WEB TECHNOLGY 200
9
This method immediately sends any previously buffered output to the
client but continues the processing of the script.
Syntax:
<%response.flush%>
SESSION OBJECT
Session Object maintains a connection between an ASP application and
each user. The session object prevents users from having to authenticate
repeatedly.
Session object helps to maintain variables or information required for the
entire session.
Session object relies on cookies.
An overview of session object
Collections Events Methods Properties
Contents Onstart Abandon Codepage
Contents.remove SessionID
all
TimeOut
Properties
Session: The interval an user spends after he has made a request to one
of the pages and before the user abandons it either through the code or
after the specified timeout value has reached is called a session.
Session Id: Each user is given an unique number usually known as
sessionid at the beginning of his session that is stored on the web server.
1
WEB TECHNOLGY 200
9
The sessionid is then written automatically into a cookie on the client’s
machine.
The sessionid value can be determined from within an ASP script as
follows
<% dim idval
Idval=session.sessio
nID
%>
Timeout: A timeout can also be set for the user sessions. The time period
for which the server will maintain a session for a user can be important.
Default timeout is 20 minutes.
Note: the default timeout depends on the version of IIS.
Syntax:
<%session.timeout=time in minutes
%>
Session.codepage
=ID
LCID: The acronym for LCID is Location Identifier. The user can set his
ASPs to use a specific system locale by setting the location identifier. This
helps to set the locale for an ASP to present information in a more suitable
manner.
3
WEB TECHNOLGY 200
9
Syntax:
Session.LCID=val
ue
Events
Onstart: This event is triggered when a user who has not instantiated a
session on the web server requests any page from the server i.e., begins a
session.
The code for this event if exists resides in the global.asa file. This code is
executed well before executing any code of the requested page.
Sub
session_onstart
----------
----------
End sub
Onend: This event is triggered either when the user’s session times out or
when the ASP program invokes the abandon method of the session object.
The code
Sub
for this event if exists resides in global.asa file.
session_onend
----------
1
----------
WEB TECHNOLGY 200
9
Methods
Abandon: The session object’s abandon method can be used to clear all
the session variables in one step.
Syntax:
Session.aband
on
Session.contents.remov
eall
3
WEB TECHNOLGY 200
9
APPLICATION OBJECT
Application Object basically all of the files contained within a virtual
directory and all of its subdirectories. So a collection of files that make up
a particular ASPs site are referred to as ASPs applications or ASP
applications.
The user can also access all of the global variables and objects that are in
global, as a file, through the use of Application Object.
Collections Events Methods Properties
Contents OnEnd Contents.remove
Unlock
Application.lock
Statements
1
Application.unlock
%>
WEB TECHNOLGY 200
9
SERVER OBJECT
The server object is the web server. This object is used to incorporate
some of the server’s own functionality into the ASPs. The object can be
used to handle script time outs to execute other ASPs from within an ASP.
An overview of server object
Collections Events Methods Properties
Createobject scriptTimeOut
Execute
Getlasterror
HTMLencode
Mappath
Transfer
URL Encode
PROPERTIES
ScriptTimeOut: The server object’s ScriptTimeOut property is used to set
a timeout for the ASPs. The default time out for every script in ASP is 90
seconds unless the timeout is altered explicitly.
1
WEB TECHNOLGY 200
9
Syntax:
Server.scripttimeout=an
integer value
METHODS
CreateObject: method is used to create an instance of non-intrinsic
objects.
Syntax:
Server.execute(“name of ASP
file”)
MapPath: is used to determine the physical path of the file. This method
takes virtual path or relative path as a parameter and converts it into a
physical path.
Syntax:
String name=server.mappath(“virtual
string”)
1
WEB TECHNOLGY 200
9
Transfer: method is like the execute method, but does not return to the
original script.
Syntax:
Server.transfer(“name of a different ASP
file”)
Set
strvariable=server.getlasterr
Strvariavle=server.URLEncode(“URL
string”)
2
WEB TECHNOLGY 200
9
METHODS
Set Abort: If a transaction has become a failure, the entire transaction
should be aborted.
Syntax:
Objectcontext.seta
bort
Set Complete: this method can be invoked to indicate the transaction is
being successful.
Syntax:
Objectcontext.setcomp
lete
1
WEB TECHNOLGY 200
9
EVENTS
Ontransactioncommit: helps to use a sub routine that informs the user
of the success of a particular transaction that was requested.
Syntax:
<%
Sub
ontransactioncommit
-------------------
-------------------
End sub
%>
Ontransactionabort: is used when the user is able to use a subroutine
that informs the user of the failure for the particular transaction that was
requested.
Syntax:
<%
Sub
ontransactionabort
---------------
---------------
End sub
%>
3
WEB TECHNOLGY 200
9
ASPdescription
Category
Column
Description
File
Line
Number
Source
1
WEB TECHNOLGY 200
9
ASPcode property is a code that IIS assign to specify ASP’S error.
Source property displays the actual line of script where the error
occurred. It is helpful with syntax error.