Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

ASP Tutorial
ASP Introduction
Run An ASP Web Page
ASP First Script
ASP Programming-VBScript
Variables in ASP
Array in ASP
Operators in ASP
ASP If Statements
ASP Select Statements
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
Application in ASP
ASP #include
ASP Global.asa
ASP Send e-mail
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error
ASP FileSystem
ASP TextStream
ASP Drive
ASP File
ASP Folder
ASP Dictionary
ASP ADO
ASP Ad Rotator
ASP Browser Cap
ASP Content Linking
ASP Content Rotator
ASP Quick Reference
ASP Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Global.asa in ASP

Previoushome Next



  • In an ASP application,the Global.asa file is an optional file that stores declarations of objects, variables, and methods that can be accessed by every page


A D V E R T I S E M E N T



The Global.asa file

In an ASP application,the Global.asa file is an optional file that stores declarations of objects, variables, and methods that can be accessed by every page . Global.asa file uses all valid browser scripts (JavaScript, VBScript, JScript, PerlScript, etc.) The Global.asa file stores only the following:

  • Application events
  • Session events
  • <object> declarations 
  • TypeLibrary declarations
  • the #include directive

Note: Each application can only have one Global.asa file and the Global.asa file must be stored in the root directory of the ASP application.

Events in Global.asa

when the application/session starts or application/session ends ,it is necessary to tell the application and session objects in Glogal.asa about the work to be done. The code for this is placed in event handlers. The Global.asa file uses four types of events:

Application_OnStart - This event occurs in an ASP application when the FIRST user calls the first page from . This event occurs after the Global.asa file is edited or after the Web server is restarted. The "Session_OnStart" event occurs immediately after this event.

Session_OnStart - In the ASP application,this event occurs EVERY time a NEW user requests his or her first page .

Session_OnEnd - EVERY time a user ends a session, this event occurs. After a page has not been requested by the user for a specified time (by default this is 20 minutes),a user ends a session .

Application_OnEnd - Aafter the LAST user has ended the session,this event occurs. Typically, this event occurs when a Web server stops. To clean up settings after the Application stops,this procedure is used like delete records or write information to text files.

A Global.asa file could look something like this:

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

Because to insert scripts in the Global.asa file we cannot use the ASP script delimiters (<% and %>), we put subroutines inside an HTML <script> element




<object> Declarations

With the help of <object> tag it is possible to create objects with session or application scope in Global.asa .

Note: The <object> tag should be outside the <script>tag

Syntax:

<object runat="server" scope="scope" id="id"
{progid="progID"|classid="classID"}>
....
</object>
Parameter Description
scope Sets the scope of the object (either Session or Application)
id Specifies a unique id for the object
ProgID An id associated with a class id. The format for ProgID is [Vendor.]Component[.Version]

Either ProgID or ClassID must be specified.

ClassID Specifies a unique id for a COM class object.

Either ProgID or ClassID must be specified.




Examples

The first example creates an object of session scope named "MyCreate" by using the ProgID parameter:

<object runat="server" scope="session" id="MyCreate"
progid="MSWC.AdRotator">
</object>

The second example creates an object of application scope named "MyConnection" by using the ClassID parameter:

<object runat="server" scope="application" id="MyConnection"
classid="Clsid:8AD3067A-B3FC-11CF-A560-00A0C9081C21">
</object>

In the application,the objects declared in the Global.asa file can be used by any script :

GLOBAL.ASA:<object runat="server" scope="session" id="MyAd"
progid="MSWC.AdRotator">
</object>

You could reference the object "MyAd" from any page in the ASP application:

SOME .ASP FILE:


<%=MyAd.GetAdvertisement("/banners/adrot.txt")%> 


TypeLibrary Declarations

A TypeLibrary is a container that stores DLL file corresponding to a COM object. By including a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. You can declare the type libraries in Global.asa if your Web application relies on COM objects that have declared data types in type libraries,

Syntax

<!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
-->
Parameter Description
file

Specifies an absolute path to a type library.

Either the file parameter or the uuid parameter is required
uuid Specifies a unique identifier for the type library.

Either the file parameter or the uuid parameter is required

Version

Optional. Used for selecting version. If the requested version is not found, then the most recent version is used

lcid

Optional. The locale identifier to be used for the type library

Error Values

The following error messages can return by the server :

Error Code Description
ASP 0222

Invalid type library specification

ASP 0223 Type library not found
ASP 0224

Type library cannot be loaded

ASP 0225 Type library cannot be wrapped

Note:

In the Global.asa file, METADATA tags can appear anywhere (both inside and outside <script> tags). However, it is recommended that METADATA tags appear near the top of the Global.asa file.



Restrictions

You can include restrictions in the Global.asa file:
  • The text that is written in the Global.asa file can not be displayed. This file can't display information

  • in the Application_OnStart and Application_OnEnd subroutines,you can only use Server and Application objects . In the Session_OnEnd subroutine, you can use Server, Application, and Session objects. You can use any built-in object in the Session_OnStart subroutine

How to use the Subroutines

To initialize variables.  Global.asa is often used.

The example below shows how to detect the exact time a visitor first arrives on a Web site. The time is stored in a Session variable named "started", and in the application,the value of the "started" variable can be accessed from any ASP page :

<script language="vbscript" runat="server">
sub Session_OnStart
Session("started")=now()
end sub
</script>

To control page access, Global.asa can also be used .

The example below shows how to redirect every new visitor to another page, in this case to a page called "newpage.asp":

<script language="vbscript" runat="server">
sub Session_OnStart
Response.Redirect("newpage.asp")
end sub
</script>
And you can include functions in the Global.asa file.

In the example below when the Web server starts,the Application_OnStart subroutine occurs . Then the Application_OnStart subroutine calls another subroutine named "getusers". The "getusers" subroutine opens a database and retrieves a record set from the "users" table. The record set is assigned to an array, where it can be accessed from any ASP page without querying the database

<script language="vbscript" runat="server">
sub Application_OnStart
getusers
end sub
sub getusers 
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=conn.execute("select name from users")
Application("users")=rs.GetRows
rs.Close
conn.Close
end sub

Global.asa Example

In this example we will create a Global.asa file that counts the number of current visitors.

  • When the server starts,the Application_OnStart sets the Application variable "visitors" to 0

  • Every time a new visitor arrives,the Session_OnStart subroutine adds one to the variable "visitors"

  • The Session_OnEnd subroutine subtracts one from "visitors" each time this subroutine is triggered

The Global.asa file:

<script language="vbscript" runat="server">
Sub Application_OnStart
Application("visitors")=0
End Sub
Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub
</script>
In an ASP file,to display the number of current visitors is given below:
<html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%> online now!
</p>
</body>
</html>

Be the first one to comment on this page.




  ASP Tutorial eBooks
More Links » »
 
 ASP Tutorial FAQs
More Links » »
 
 ASP Tutorial Interview Questions
More Links » »
 
 ASP Tutorial Articles

No ASP Articles could be found as of now.

 
 ASP Tutorial News

No News on ASP could be found as of now.

 
 ASP Tutorial Jobs

No ASP Articles could be found as of now.


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: application performance with object caching, application object pdf, application variables, application scope

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.