ASP Hosting sale!
1,000MB space, 40GB transfer, 1 SQL Server 2000 db! - $9.95 per month*!
Limited Time Offer!

aspdev | articles | tutorials | forums

ASPdev -> ASP Tutorial -> ASP Global.asa

ASP Global.asa

The Global.asa file is a file that can hold Application & Session event handlers and declarations of objects & variables, which are accessible from all pages in an ASP application. The Global.asa file is optional, but if presented it should be placed in the root ASP application folder.

The Global.asa can contain the following Application events:

The Global.asa file can define what happens when certain event takes place. For example when a new user Session starts/end or an Application starts/ends. The code that defines what happens when any of those events occur resides in the so-called event handlers subroutines. There are 4 events that can be handled in Global.asa and there are 4 corresponding event handlers that can be used in the Global.asa file:

Application_OnStart event occurs when the ASP application is executed for a first time. (the very first call for an ASP page within this application). This event is handled within the Application_OnStart subroutine:

Sub Application_OnStart
Application on start handling code here
End Sub

Application_OnEnd event occurs when there are no more active user sessions. Typically, this event occurs when a Web server stops. This event is handled within the Application_OnEnd subroutine:

Sub Application_OnEnd
Application on end handling code here
End Sub


Session_OnStart event occurs when a new user requests his first ASP page from an ASP application. This event is handled within the Session_OnStart subroutine:

Sub Session_OnStart
Session on start handling code here
End Sub


Session_OnEnd - event occurs when a user browser session end. The user browser session ends when the user closes the browser or after a period of inactivity (the user browses an ASP application and then leaves his browser open without interacting with the application for extended period of time). This event is handled within the Session_OnEnd subroutine:

Sub Session_OnEnd
Session on end handling code here
End Sub

<object> tag

You can create objects within Global.asa file, which are accessible for all or for particular user, depending of their scope, by using the <object> tag:

<object runat="server" scope="application" id="YourObjectID" progid="Scripting.Dictionary"></object>




Contact Us