Chapter 39: ASP Global.asa file

1. What is the global.asa file?

global.asa is a special file that must be placed in the root folder of your Classic ASP website.

It is not a normal .asp page — it never gets served directly to the browser (if someone tries to access http://yoursite.com/global.asa → 404 or forbidden).

Instead, IIS automatically runs code inside global.asa at four very specific moments in the life of the application:

Event name When it runs Typical use case in real Classic ASP sites
Application_OnStart First time any user visits the site after IIS restart or app pool recycle Set global variables, cache lookup tables, open shared connections, initialize counters
Application_OnEnd When the application shuts down (IIS restart, app pool recycle, server shutdown) Clean up resources, log shutdown time (rarely used)
Session_OnStart Every time a new user session begins Initialize per-user variables, log new visitor, set default language
Session_OnEnd When a user session ends (browser closes or Session.Abandon or timeout) Log logout time, clean up per-user resources (rarely reliable)

Key facts you must remember:

  • File name must be exactly global.asa (lowercase, .asa extension)
  • Must be in the root folder of the website (not in a subfolder)
  • Uses special <script runat=”server”> tags — not normal <% %> blocks
  • Only VBScript or JScript allowed (VBScript is 99% of cases)

2. Basic Structure of global.asa

asp

Very important notes:

  • All four Subs are optional — you can have only the ones you need
  • Application.Lock / Unlock is mandatory when modifying Application variables
  • Session_OnEnd is not reliable for critical cleanup — many browsers don’t fire it when tab closes

3. Real-World Example 1 – Visitor Counter + Site Settings

Most classic ASP homepages in 2000–2005 had a “You are visitor #XXXXX” line — this is how it was done.

asp

Then in any page (e.g. default.asp):

asp

4. Real-World Example 2 – Cached Categories Menu (Very Common)

asp

Then in any page (e.g. sidebar include):

asp

→ Database hit once on app start → every page reads from memory → fast!

5. Important Rules & Warnings (2026 Reality)

  • global.asa must be in root folder — not in /includes or subfolder
  • Only one global.asa per site — IIS ignores others
  • Changes to global.asa require IIS restart or app pool recycle to take effect
  • Lock / Unlock every time you write to Application variables
  • Do NOT store sensitive data in Application — it is readable by all users
  • Session_OnEnd is unreliable — many browsers don’t trigger it on tab close
  • In 2026 legacy systems → still used for config, counters, cached menus, but very risky if not locked properly

6. Teacher Summary – The global.asa File in Classic ASP

global.asa is:

  • A special file in the root folder that never gets served to browsers
  • Contains four special Subs: Application_OnStart, Application_OnEnd, Session_OnStart, Session_OnEnd
  • Runs automatically on app start / new session / shutdown
  • Main uses: set global constants, cache lookup data, initialize counters, set session defaults
  • Application_OnStart = perfect place to load shared config or cache
  • Session_OnStart = good for visitor counters, default preferences
  • Lock / Unlock mandatory when modifying Application variables
  • Session_OnEnd — avoid relying on it for cleanup

This is how millions of Classic ASP sites initialized global settings, cached data, and tracked visitors — and many legacy Indian internal systems, ERPs, and small-business portals still use exactly this global.asa pattern in 2026.

Next class?

  • Want a full example with global.asa + Session + Cookies + login?
  • Or how to debug when global.asa doesn’t run?
  • Or compare global.asa vs modern ASP.NET Core Startup/Program.cs?
  • Or move to the next W3Schools topic (ASP Include again or ASP Cookies)?

Just tell me — I’m here! 🚀🇮🇳 Keep going strong, Webliance! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *