Anda di halaman 1dari 18

Active Server Pages

Development with ASP


Contents
• ASP Variables
• ASP objects and Components
– Request object
– Response object
– Application object
– Session object
– Server object
• Server-side includes
• Global.asa file

2
ASP Variables
A variable is used to store information.
• Session Variables
– Session variables are used to collect information
regarding a single user.
– They are accessible by all pages in one application.
– Usually, the information about the name, id, preferences
about a user are stored in session variables.
• Application Variables
– Application variables can also be accessed by all pages
in one application.
– They are utilized to store information about all the users
in one particular application.

3
ASP Objects and Components
Active Server Architecture
ASP.DLL
ASP offers a list Request
of objects and ASP
components that Error Response
handle the Scripting
interface between Engine
the web server and Server Application
the browser.
Session

4
Intrinsic Objects of ASP-
Request Object
Request Object:
It is utilized to get information from the user.
Example: When a browser asks for a page from a server, it is
called as a request.

Property Description
TotalBytes It returns total bytes present in the body of the
request which the client sent.

Method Description
BinaryRead It gets the data sent from the client to the server as
part of a post request and saves it in the form of an
array.

5
Intrinsic Objects of ASP-
Response Object

Response Object:
It is used to dispatch the output to the user from the server

Property Description
Buffer It denotes whether to buffer the page output or not
Status It denotes the value of the status line returned by the server

Method Description
Write It writes a specified string to the output
Redirect It redirects the user to another URL

6
Intrinsic Objects of ASP-
Application Object

Application Object:
A collection of ASP files that work collectively to execute some
function is called an application.
The Application object in ASP is used to bind these files together.

Method Description
Contents.Remove It removes an item from the Contents collection
Contents.RemoveAll It removes all items from the Contents collection
Lock It prohibits the other users from changing the
variables in the Application object
UnLock It enables other users to alter the variables in the
Application object once it has been locked using
the Lock method
7
Intrinsic Objects of ASP-
Application Object

Event Description
Application_OnEnd It arises when all user sessions are ended and
the application ends
Application_OnStart It happens before the first new session is
constructed i.e. when the Application object is
referenced for the first time.

8
Intrinsic Objects of ASP-
Session Object
Session Object:
It is used to store information about a specific user’s session.
The variables present in the Session object contain information
about a single user and are accessible by all pages in one
application.

Property Description
SessionID It returns a distinct id for each user which is generated
by the server
Timeout It sets or returns the timeout interval in minutes for the
application’s session object.

9
Intrinsic Objects of ASP-
Session Object
Method Description
Abandon It destroys a user session
Contents.Remove It deletes an item from the Contents collection

Event Description
Session_OnEnd It happens when all user sessions are finished
and the application ends
Session_OnStart It happens before the first new session is
constructed i.e. when the Application object is
referenced for the first time.

10
Intrinsic Objects of ASP-
Server Object

Server Object:
It is used to access properties and methods on the server.

Property Description
ScriptTimeout It sets or returns the utmost number of seconds a
script can run before it is terminated

Method Description
CreateObject It creates an instance of an object
Execute It executes an ASP file from another ASP file

11
Intrinsic Objects of ASP-
Error Object
ASPError Object:
It is used to display detailed information of any error
that occurs in scripts in an ASP page.

Property Description
ASPCode It returns an error code generated by IIS
ASPDescription It returns a detailed description of the error

File It returns the name of the ASP file that generated the
error
Line It returns the line number where the error was found
Source It returns the actual source code of the line where the
error arised
12
Server-side includes
MyWebPage.asp Welcome.inc
“I welcome each one of you to
<html> be a part of Accenture family”
<body>
<h3>Welcome to Accenture</h3>
<p><!--#include file="welcome.inc"--></p>
<h3>The time is:</h3>
<p><!--#include file="time.inc"--></p>
</body>
</html>
time.inc
<% Response.Write(Time) %>
• The #include directive is used to include the content of one ASP file
into a different ASP file before the execution process by the server.

• It is used to construct functions, headers, footers or elements that will


be reused on several pages.

13
Global.asa file
• It must be stored in the root directory of the
application.

• An application can only have one Global.asa file.


• Most of the suitable browser scripts like JavaScript,
JScript, VBScript, PerlScript etc can be utilized inside
Global.asa file.

The Global.asa is an optional file that


holds information about object, variables,
methods and events that can be accessed by
all web pages in an application
14
Global.asa file

Global.asa file

Application events

Application_OnStart Application_OnEnd

Session events

Session_OnStart Session_OnEnd

<object>
declarations
TypeLibrary
declarations 15
Global.asa file
<script language="vbscript" runat="server">
sub Application_OnStart
'''‘some code
end sub
sub Application_OnEnd
''''some code
end sub
sub Session_OnStart
'''‘some code
end sub
sub Session_OnEnd
'''some code
end sub
</script>

16
Questions and Comments

What questions or comments do you have?

17
Key Points
• ASP offers a list of objects and components that handle the interface
between the web server and the browser.

• Request object is utilized to get information from the user.

• Response object is used to dispatch the output to the user from the server

• Application object is used to bind the files of an application together.

• Server object is used to access properties and methods on the server.

• Error object is used to display detailed information of any error that occurs
in scripts in an ASP page.

• The #include directive is used to include the content of one ASP file into a
different ASP file before the execution process by the server.

• The Global.asa is an optional file that holds information about object,


variables, methods and events that can be accessed by all web pages in
an application
18

Anda mungkin juga menyukai