0% found this document useful (0 votes)
6 views

my

The document discusses ASP objects, including REQUEST, RESPONSE, SESSION, APPLICATION, and SERVER, which are used to handle user requests and server responses in database applications. It details the properties, methods, and collections associated with each object, explaining how they facilitate data retrieval, storage, and communication between the client and server. Additionally, it outlines the functionality of each object, such as managing user sessions and application-level variables.

Uploaded by

M Mussawar Sher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

my

The document discusses ASP objects, including REQUEST, RESPONSE, SESSION, APPLICATION, and SERVER, which are used to handle user requests and server responses in database applications. It details the properties, methods, and collections associated with each object, explaining how they facilitate data retrieval, storage, and communication between the client and server. Additionally, it outlines the functionality of each object, such as managing user sessions and application-level variables.

Uploaded by

M Mussawar Sher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

chap 22

ASP OBJECTS:
The nuser sends request to the server and recieves
response from it. In any database application we need to have
objects of different types to get data from the user and to display the
data receives from the database stored on the server. Similarly we
need to access resources of server etc. ASP provides objects for this
purpose. It provides the following intrinsic objects:
REQUEST
RESPONSE
SESSION
APPLICATION
SERVER

REQUEST OBJECT:
When a browser ask for a page from a server, it is called a
request. The ASP Request object is used to get information from the
user. It makes available all then values that the client browser
passes to the server through FORM. The collections, properties and
Methods of Request object are described below:-

COLLECTION:
Page 1
chap 22
1) ClientCertificate: It makes available a collection off all
field values stored in the client certificate that is sent to the HTTP
request. Before using this collection the server should be configured
to request client certificates.
2) Cookies: It makes available all the cookies stored in the
client browser. We can use the cookies collection to retrieve any
cookie value.
3) Form: It contains all the form(input) values from a Form
submitted usingn POST method.
4) QueryString: It contain all the variable values in an
HTTP query string. Usually, it is used to maccess variables sent with
URL after "?" sign or from a Form submitted using GET method.
5) ServerVariables: It contain all the server variable's
values. It also contains a collection of all the nHTTP header values
sent from the client browser to the server. You can retrieve the
server variable values and header values.
The syntax to use this collection is
Request.ServerVariables(server_variable)

The syntax to access the variable of any of these collections is;


Request.collections("variable")
The use of word "collections" is optional. So the above syntax can
be written as:
Page 2
chap 22
Request("variable")
When we use the Form collection, we need to pass the name of the
element that we crteate in HTML Form as a variable to the requewst
Object.
For example, if you have created a text box as given below:
<INPUT Type="text" Name="Text1" value=" " >
The Request statement should be: Request.Form("Text1")
OR Request(*"Text1")

PROPERTIES:
1) TotalBytes: It is read-only property. it returnes the total
num,ber of bytes the client browser has sent top the server with the
request.

METHODS:
1) BinaryRead: It is used nto retrieve the dtat sent to the
server from the client as a part of na POST request. It stores all thius
data in a safe array (an array that stores information aboput the
nuymber of dimensions and the bounds of its dimensions).
The syntax of this method is:
Request>BinaryRead(count)
Where count specifies how many bytes to read from the
client.
Page 3
chap 22

RESPONSE OBJECT:
The Response object is used to send information/data top
the user from the server. It includes all the HTTP variables, cookies
that will be stored on the client browser and other information
aboput the contnt being sent. Its collections, properties and methods
are deswcribed below:

COLLECTIONS:
1) Cookies: It is used to specify the values of cookies, which
will be sent back to the client browser.

PROPERTIES:
1) Buffer: It is used to specify whether to buffer the page
output or not. It is a bolean value. If the page Response.Buffer
property is set to true then the output from from the page willnot be
sent to the client untill all the script in that paage is processed.
Please note that in IIS 5, Response.Buffer is by default set to true.
2) CacheControl: It is used to set whether a proxy server
can cache the output generated by ASP or not. It is a string value. If
Page 4
chap 22
you want proxy server to cache the output of your ASP, then set this
property to publuic. If you don't want to enable caching of your
ASP, then set it to private.
3) Charset: It is used to append the name of a characte-set
to the content-type header in the response object. For example to
specify the name of the ncaharacter set, code is written as:
<%
Response.Charset = "ISO8859-1"
%>
<HTML>
<BODY>
<P>This is some text of the
page.</p></BODY></HTML>
4) ContentType: It is used nto set the HTTP cxontent type
for thew Response object. If Response.ContentType is not specified
then by default MIME-Type "text/html" is used. For example to
specify the type of content, code is
<% Response.ContentTyope="text/html" %>
<html><body><p>this is text file
</P></body></html>
5) Expires: It is used to specify the duration of time in
minutes after which the page expires in the client browser cache.
The value '-1' is specified to refresh the page with each access. For
Page 5
chap 22
example to refresh the page bwith each access
<% Response.Expires=-1 %>
<html><body><p>page
refresh</p></body></html>
6) ExpiresAbsolute It is uesd to set date and time when a
poage cahed on qa browser will expire. For example to specify a
date/time a page cached in a browser will expire,
<% Response.ExpiresAbsolute=#May 05, 2019 10:20:30#
%>
<html><body><p> page expire on given time and date
</p></body></html>
7) IsClientConnected: It is used to know if the client has
disconnected from the server. It is boolean value. It indicastes
whther the client is still connected to this particular page. For
example
<html><body><% IF Response.IsClientConnected=true
THEN
Response.write("User
Connected")
Else
Response.write("User not
Connected")
End IF %.</body></html>
Page 6
chap 22
8) Status: It specifiews the value of the status line returned
by the server. It is included in HTTP headers of the responmse. This
string should contain both three digitsw code and a brief
explaination for it e.g. "404 fil;e Not Fopund">

METHODS:
1) AddHeader: It is used to add va new HTTP header and a
value to the HTTP response. It must be used before any text or HTML
is sent to the client. For example
Response.AddHeader "AUTHENTICATED", "You are now
logged on."
2) AppendToLog: It is used to add a string to the end of the
server log entry for this page e.g. Pesponse.AppendToLog "Your
custom log message goes here".
3) BinaryWrite: It is used to write data directly to the
output without any cahareacter-set conversion. It is useful for
writting non-string information such as binary data required by an
application or for sending bytes to make up an image.
4) Clear: It is used to cl;ear any buffered HTML output from
the IIS response buffer. Normally, it is used to abort the partly
completed page.
The following code demonstrate how you can clear the buffer:
<%Response.Buffer = true %>
Page 7
chap 22
<html><body><p>text sending to user</p><p> now aborting
</p>
<% Response.Clear %></body></html>
5) End: It is used to stop the processing of an ASP script in
the current poage and returns the current result to the client
browser. Further processing of the page is aborted. The following
code demonstrate how to terminate the execution of the script in
the middle of processing
<p> this text will never be <br>
<%
Response.End
%>
finiushed too late</p>
6) Flush: It is used to send buffered HTML output
immediately to the client. It is opposite to that of Response.Clear,
which erases the currently buffered content. Normally it is used to
send parts of long pages to the client when Response.Buffer is set to
true.
<% Response.Buffer = true %>
this is some text
<% Response.Flush %>
7) Redirect: It is used to redirect the browser to another
page or URL e.g. Response.Redirect http://www.pakman.com.pk
Page 8
chap 22
8) Write: It is used to write a specified string to the output.
for ewxample
<body> <% Response.Write("welcome") %>
</body>
You can combine text and HTML tags with ASP to format
the text
<% Response.Write("<H1> I Love Pakistan </H1>")
%>

APPLICATION OBJECT:
In other languages an application is often a single
executable file that may have many different functions. An
application on the web may be a group of ASP files within a single
directory, including any subdirectories. The ASP files work together
to perform some purpose. A group of ASP files that work together to
perform some purpose is called an application.
The application object in ASP is used to tie ASP files
together . In this way, information can be shared among the users of
the web application. This object is typically used to create variables
that maintain application level scope.
Page 9
chap 22
For example to create a variable "UserID" and assign
value "BCS001" to it,
Application("UserID") = "BCS001" OR
Application.Contents("UserID") = "BCS001"

The Application object should hold information that will be


used by many pages in the application. This means that you can
access the information from any page. You can also change the
information in one place and the changes will automatically be
reflected on all pages.

COLLECTIONS:
1) Contents: It contains a collection of all the items that
have been added to the application through a script command. You
can loop through the Contents collection using For
Each/Nextstatement to access all its contents
<% Dim i
For Each i In Application.Contents
Response.Write(i & "<BR>")
Next %>
2) StaticObjects: It contains all the objects added to the
application with the HTML <object> tag. You can also loop
..............................................................Code............
Page 10
chap 22
Application.StaticObjects.....................

METHODS:
1) Contents.Remove: It is used to delete (or remove) a
specified item from the contents collection. For example to remove
the item named "UserID" from the collection code is
Application.Contents.Remove "UserID"
2) Contents.RemoveAll: It is used to delete all items from
the contents collection. Application.Contents.RemoveAll
3) Lock: It is used to lock the application object to that only
one user at a time can modify the values of variables.
4) Unlock: It is used to unlock the application object (after
it has been locked using the LOCK method). In this way other user
can modify the variables in the Application object. For example to
lock the application and then unlock it after performing some
operations on its items/variables
<% Application.lock
'hgsjhkdjg;nejhfjv;lsdmnf
Application.unlock %>

EVENTS:
1) Application_OnStart: This event occur when the first
user calls the first page from an ASP application.
Page 11
chap 22
2) Application_OnEnd: This event occur after the last user
has ended the session. Typically, this event occur when the
application ends/stops.

SESSION OBJECT:
When you are working with an application, you open it,
perform some operations and then you close it. This is much like a
session(A session represents one user's visit to the website during
one interval of time. A new session starts as the user accesses any
page of the website and ends with the user leaves the website.) . The
Computer knows who you are. It knows the time when you start the
application and when you end. But on the internet there is one
problem.: the web server does not know who you are and what you
do because the HTTP address doesn't maintain state.
ASP solves this problem by creating a unique cookie for
each user. The cookie is sent to the client and it contains the
information that identifies the user. This interface is called the
Session Object.
The session object is used to store information about a
Page 12
chap 22
particular user. Variables stored in the session object hold
information about one single user, and are available to all pages in
one application. The server creates a new session object for each
new user, and destroys the session object when the session expires.
For example to store information about a particular user,
Session("name") = "CM"
Session("date") = "2009/02/06"

COLLECTIONS:
1) Contents: It contains all the items added to the session /
application through a script command. You Can loop
<% Session("name") = "CM"
Session("date") = "2009/06/02"
For Each i In Session.Contents
Response.Write(i & "=" & Session.Contents(i) &&
"<BR>" )
Next %>
2) StaticObjects: It contains all the objects added to the
session / appllication with the HTML <object> tag.

PROPERTIES:
1) CodePage: It specifies thje character set that will bne
used for displaying special characters. It is an integar value.
Page 13
chap 22
American english uses a particular code page, Japanese Kanji uses
another. For example code page 1252 is used for American English
and most European languages and 932 used for Japanese Kanji. To
display the code page Response.Write(Session.CodePage)
2) LCID: LCID stands for locale identifier. It is a standar
international abbreviation that uniquely identifies the locale. It is
used to set or return an nintegar that specifies a location or region.
Contents like date, time and currency will be displayed according to
that location or region.
3) SessionID: It returns a unique id value for a particular
session. The unique ID is generated by the server for each user. This
value is sent as a cookie to client. To display ID value for a particular
session Response.Write(Session.SessionID)
4) Timeout: It is used to set or return the timeoput period
(in minutes) for the session. If the client (or user) doesn't refresh or
request any page of your site within this time out period then the
server ends the cuirrent session. If you do not specify any timeout
period then by default timeout period is 20 minutes.
Top set tyhe timeout Session.timeout = 30
to display the timeout period Response.Write(Session.Timeout)

METHODS:
1) Abandon: This method is used to terminate or close a
Page 14
chap 22
current user session. It destroys the session object. So the content of
the session object are erased. The system resources that were
devoted to that particular session are also released. If the user
requests any page of you site after execution of abandon method,
then a separate session will be started.
2) Contents.Remoove: It is used to delete an item from the
contents collection.
3) Contents.RemoveAll: It is usewd to delete all items from
the contents collection.

EVENTS:
Session_OnStart: It occur when a new session starts.
2) Session_OnEnd: It occurs when a session ends ( or times
out).

SERVER OBJECT:
The Server object is designed to mprovide various services
to ASP application. Unlike the Application and Session objects,
Server object does not store the information. Usind its properties
and methods, you can create objects, execute code in other ASP
Page 15
chap 22
files, translate virtual paths to physical paths and so on.

PROPERTIES:
1) ScriptTimeout: It is used to specify the duration, in
seconds after which a script will terminate if processing is not
complete. The default value is 90 sec.

` METHODS:
1) CreateObject: It is used to create an ninstance of the
object ( a component, application or a scripting object).
2) Execute: It is used to execute an ASP page from inside
another ASP page. After executing another ASP page, control is
passed back to the bcalling page.
3) GetLastError: It is uised to get information about the last
error occured in the ASP script.
4) HTMLEncode: It provides HTML Encoding to a given
string. All non-legal HTML characters are converted to their
erquivalent HTML entity e.e. "<" is converted to &lt: .
5) MapPath: It maps the specified virtual or relative path
into physical path of the server. For example
<% Response.Write(Server.MapPath9"test.asp")) %>
The above code will return output as
C:\inetpub\wwwroot\MyWeb\test.asp
Page 16
chap 22
6) Transfer It transfer the controll from the page to aother
page specified in the URL. Unlike execute method, control is not
returned to the calling page. Usually, this method is used to send all
the information created in one ASP file to a second ASP file.
7) URLEncode: It is used to apply URL encoding rules to a
specified string.

ASP "global.asa" FILE:


The "Global.asa" is a text file that can contain
declarations opf objects, variables and methods that can be accessed
by every page in an ASP application. The Global.asa file can also
contain Application events and Session events. All valid browser
scripts (JavaScript, VBScript, JScript, PerlScript, etc.) can be used
within Global.asa. Please note that Global.asa file must be stored in
the root directory of the ASP application, and each application can
only have one "Global.asa" file.

EVENTS IN "Global.asa" FILE:


In Global.asa file you can tell the application and session
Page 17
chap 22
objects what to do when the application/session starts and what to
do when application/session ends. The code for this is placed in the
event handles. The Global.asa file can contain four types of events:
1) Application_OnStart: This event occurs when tyhe first
user cal;ls the first page from an ASP application.
2) Session_OnStart: This event occurs when a new session
starts. A new session starts as the user accesses any page of the
website. Please note that Session_OnStart event occuirs
immediatelly after Application_OnStart event.
3) Session_OnEnd: This event occurs when a session ends
(or times out). A session ends when the user leaves the website. A
session also ends when the page has not been requested by the user
for a specified time ( by default trhis is 20 minutes).
4) Application_OnEnd: This event occurs after the last user
hjas ended the session. Typically, this event occurs when the
application ends/stops. An napplication ebds when web server stops.
This procedure is used to clean up settings after the Application
stops, like delete records write information to text files .
The basic structure of Global.asa file is as follows
<Script Language="VBScript" Runat="Server" >
SUB Application_OnStart
'some code
END SUB
Page 18
chap 22
SUB Application_OnEnd
'some code
END SUB
SUB Session_OnStart
'some code
END SUB
SUB Session_OnEnd
'some code
END SUB
</Script>

It may be noted that we cannot use the ASP mscript


delimeters <% and %> to insert scriptys in the Global.asa file. We
put subroutines inside an HTML <script> and </script>.

Page 19

You might also like