๐Ÿ’ป Classic ASP โ€“ Logic & Scripting
Estimated reading: 3 minutes 305 views

Classic ASP โ€“ Global.asa โ€“ Configure Application and Session Events

Introduction โ€“ What Is Global.asa in Classic ASP?

In Classic ASP, the Global.asa file is a special configuration file that defines global settings and event-handling logic for your ASP application. It enables you to manage key lifecycle events such as when an application or session starts or ends, and to register objects and variables at a global level.

In this guide, youโ€™ll learn:

  • What the Global.asa file is and where to place it
  • The four key ASP event handlers inside Global.asa
  • How to use Application and Session objects for shared data
  • Real-world examples and best practices

Where Is Global.asa Located?

  • It must be placed in the root directory of your ASP application.
  • It is automatically recognized by IISโ€”you donโ€™t need to include or link it.
/MyASPApp/
โ”‚
โ”œโ”€โ”€ global.asa
โ”œโ”€โ”€ index.asp
โ”œโ”€โ”€ login.asp

Structure of Global.asa

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
    ' Initialize application-wide variables
    Application("AppName") = "My Classic ASP Site"
End Sub

Sub Application_OnEnd
    ' Clean up application resources
End Sub

Sub Session_OnStart
    ' Initialize session variables
    Session("UserName") = "Guest"
End Sub

Sub Session_OnEnd
    ' Clean up session data
End Sub

</SCRIPT>

Event Handlers in Global.asa

EventDescription
Application_OnStartRuns once when the application first starts (after restart or deployment)
Application_OnEndRuns once when the application shuts down (e.g., server stop)
Session_OnStartRuns each time a new user session begins
Session_OnEndRuns when a session times out or is explicitly ended

Example โ€“ Set App and Session Variables

Sub Application_OnStart
    Application("Version") = "1.0"
    Application("TotalVisits") = 0
End Sub

Sub Session_OnStart
    Application("TotalVisits") = Application("TotalVisits") + 1
    Session("IsLoggedIn") = False
End Sub

Output when Session_OnStart fires:

  • TotalVisits increases
  • IsLoggedIn is initialized

Accessing Values Set in Global.asa

<%
Response.Write "App Version: " & Application("Version") & "<br>"
Response.Write "Visits: " & Application("TotalVisits") & "<br>"
Response.Write "Logged In: " & Session("IsLoggedIn")
%>

Session Timeout Configuration (Optional)

To set the default session timeout globally:

Sub Session_OnStart
    Session.Timeout = 20 ' In minutes
End Sub

Limitations of Global.asa

LimitationNotes
Works only in IISNot recognized in non-Microsoft environments
Cannot use external includes#include does not work inside Global.asa
No HTML allowedIt is not a webpage, only ASP/VBScript logic in <SCRIPT> tags

Best Practices for Global.asa

Do:

  • Keep Global.asa lean and event-driven
  • Use it for app-wide counters, configs, and session tracking
  • Store read-only settings or pre-load data

Avoid:

  • Storing sensitive information
  • Running complex logic or DB operations inside event handlers
  • Using it to replace modular includes or config systems

Summary โ€“ Recap & Next Steps

The Global.asa file is a central event script that lets you manage application and session lifecycle events. Itโ€™s a powerful feature in Classic ASP for controlling global behavior and initializing default states.

Key Takeaways:

  • Handles Application_OnStart, Session_OnStart, and their end events
  • Ideal for initializing counters, configs, and default values
  • Placed in the application root; no need to reference manually

Real-world Use Cases:

  • Visitor counters
  • Site-wide configuration variables
  • Default session state like “guest” access

FAQs โ€“ Classic ASP Global.asa


Where should I place the Global.asa file?
It must be in the root directory of your Classic ASP application.


Do I need to include or reference Global.asa?
No. IIS automatically detects and runs it when appropriate.


Can I use #include inside Global.asa?
No. #include directives are not supported in Global.asa.


Share Now :
Share

๐ŸŒ Classic ASP โ€“ Global.asa

Or Copy Link

CONTENTS
Scroll to Top