Global.asa
The Global.asa File in ASP
The Global.asa file is an optional ASP file used to define global objects, variables, and event-handling code that can be accessed by every page in an ASP application.
All valid scripting languages supported by browsers—such as VBScript, JavaScript, JScript, PerlScript, etc.—can be used inside the Global.asa file.
What Can Global.asa Contain?
The Global.asa file is restricted to the following elements only:
Application events
Session events
TypeLibrary declarations
#include directives
⚠️ Important Notes:
Global.asa must be placed in the root directory of the ASP application
Each ASP application can have only one Global.asa file
Events in Global.asa
Global.asa allows you to define what happens when an application or session starts or ends. These actions are written inside event handlers.
There are four types of events available:
1. Application_OnStart
Triggered when the first user accesses the application after:
The web server starts
The Global.asa file is modified
Immediately after this event, Session_OnStart is executed.
2. Session_OnStart
Occurs every time a new user requests their first page in the application.
3. Session_OnEnd
Occurs when a user session ends due to inactivity (default timeout is 20 minutes).
4. Application_OnEnd
Triggered after the last active user session ends, usually when the web server shuts down.
This event is commonly used for cleanup tasks such as logging data or deleting records.
Sample Global.asa Structure
📌 Note:
ASP script delimiters (<% %>) cannot be used in Global.asa. All procedures must be placed inside a
This stores the time a user first visits the site.
Redirecting Users on Session Start
All new users are redirected automatically.
Using Functions in Global.asa
Example: Loading Data Once on Startup
This loads database data once and makes it available to all pages without repeated queries.
Global.asa Example: Visitor Counter
Global.asa File:
Display Visitor Count:
There are <% Response.Write(Application("visitors")) %> online now!
Declarations in Global.asa
You can create objects with Application or Session scope using the
The