Chapter 37: ASP Application
1. What is the Application Object in Classic ASP?
The Application object is a global, shared storage area that belongs to the entire web application (i.e., your whole website), not to individual users.
It lets you store data that:
- is the same for every visitor
- survives across all page requests and all users
- lives until IIS restarts, the application pool recycles, or you explicitly clear it
- is shared and visible to every single user session
Think of it like a public bulletin board for your website:
- Session = private notepad for each user
- Application = shared whiteboard everyone can read (and sometimes write to)
Typical real-world uses in Classic ASP (2000–2010 era):
- Site-wide settings (company name, phone number, email, version number)
- Global counters (total visitors today, number of active users)
- Cached data (lookup tables, menus, configuration from database)
- Application-level locks for safe multi-user updates
- Simple statistics or flags (site under maintenance, holiday mode)
2. Core Properties & Methods You Must Know
| Property / Method | What it does | Example |
|---|---|---|
| Application(“key”) = value | Store any value (string, number, array, object) | Application(“SiteName”) = “Webliance Shop” |
| value = Application(“key”) | Read stored value | site = Application(“SiteName”) |
| Application.Contents.Remove(“key”) | Delete one item | Application.Contents.Remove(“VisitorCount”) |
| Application.Contents.RemoveAll | Delete all items | Application.Contents.RemoveAll |
| Application.Lock | Prevent other requests from reading/writing Application | Before updating shared counter |
| Application.Unlock | Release the lock | After update is done |
Very important rule (write this 10 times):
Always use Application.Lock and Application.Unlock when you write to Application variables — otherwise two users can update the same value at the same time → data corruption.
3. Basic Example 1 – Simple Site-Wide Setting
File: default.asp (or any page)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h1>Welcome to <%= Application("SiteName") %></h1> <p>Phone: <%= Application("SupportPhone") %></p> <p>Email: <%= Application("SupportEmail") %></p> </body> </html> |
Where to set them? Best place: a file that runs once when the application starts — usually global.asa
File: global.asa (must be in root folder)
|
0 1 2 3 4 5 6 |
<script language="VBScript" runat="server"> Sub Application_OnStart Application("SiteName") = "Webliance Hyderabad Store" Application("SupportPhone") = "+91-40-12345678" Application("SupportEmail") = "support@webliance.in" Application("VisitorCount") = 0 End Sub </script> |
→ Application_OnStart runs only once when the first user hits the site (or after IIS restart).
4. Example 2 – Global Visitor Counter (Classic Pattern)
This was extremely common in 2000–2005 homepages.
|
0 1 2 3 4 5 6 |
<!-- Put this in every page or in an include file --> <% Application.Lock Application("VisitorCount") = Application("VisitorCount") + 1 Application.Unlock Response.Write "<p>You are visitor number " & Application("VisitorCount") & " today!</p>" %> |
Why Lock / Unlock is critical:
Without it:
- User A reads 1000
- User B reads 1000
- User A writes 1001
- User B writes 1001 → counter only increases by 1 instead of 2 (lost increment!)
With Lock / Unlock:
- Only one request can modify at a time — safe increment
5. Example 3 – Cached Lookup Table (Very Real-World Use)
|
0 1 2 3 4 5 6 |
<!-- In global.asa or a startup include --> <% Sub Application_OnStart Dim conn, rs, dict Set dict = Server.CreateObject("Scripting.Dictionary") Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb") Set rs = conn.Execute("SELECT CategoryID, CategoryName FROM Categories") Do While Not rs.EOF dict.Add rs("CategoryID"), rs("CategoryName") rs.MoveNext Loop Application("Categories") = dict rs.Close conn.Close End Sub %> <!-- Then in any product page --> <% Dim catID, catName catID = 5 ' from product record If Not Application("Categories") Is Nothing Then catName = Application("Categories")(catID) Response.Write "Category: " & Server.HTMLEncode(catName) End If %> |
→ Caching lookup data in Application → huge performance win (no DB hit on every page).
6. Important Rules & Warnings (2026 Perspective)
- Never store sensitive data in Application — it is shared by everyone
- Lock / Unlock every time you write — reading is safe without lock
- Application variables survive IIS restarts / app pool recycle only if you reload them in Application_OnStart
- Application.Contents.RemoveAll clears everything but keeps application alive
- In real 2000s sites → used heavily for config, counters, cached menus
- In 2026 → still used in legacy systems, but modern .NET uses IMemoryCache, IDistributedCache, or appsettings.json
7. Teacher Summary – ASP Application Object in Classic ASP
ASP Application Object means:
- Global shared storage for the entire website
- Set with Application(“key”) = value
- Read with value = Application(“key”)
- Survives until IIS restart / app pool recycle (reload in Application_OnStart)
- Use Application.Lock / Application.Unlock when writing (critical!)
- Can store strings, numbers, arrays, dictionaries, Recordsets, objects
- Used for: site config, global counters, cached lookups, shared flags
- Never use for user-specific data — that’s Session
- Always protect writes with Lock/Unlock to avoid race conditions
This is how millions of sites stored shared settings, counters, and cached data in the 2000s — and many legacy Indian internal systems, ERPs, and government portals still use exactly this Application pattern in 2026.
Next class?
- Want a full example combining Application + Session + Cookies?
- Or how to safely update a shared counter with Lock?
- Or compare Classic ASP Application vs modern ASP.NET Core IMemoryCache?
- Or move to the next W3Schools topic (ASP Include or ASP Cookies again)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
