Specify Application start and end procedures in the Global.asa file.
Using the Global.asa File with Applications
Sometimes you will want to create objects that are available to all the users in an application. As with Session variables, you will want to initialize those objects and maybe work with some when an application begins.
You may want to initialize an Application variable as well, which you do before the application runs. The Global.asa file also lets you define code to initialize (or finish) use of an application. Recall that ASP looks for the Global.asa file in the root directory of the application.
Implementing an Application variable
For example, suppose you wanted to track the number of users who are visiting your site at any given time. You'd need to do this in several steps:
Initialize an Application variable in the Application_OnStart procedure (so it is initialized when the first user arrives).
For each new user session started, increment the value in the Application variable.
When each session ends, decrement the value in the Application variable.
Get the value of the Application variable when you need it.
You already know that ASP can detect a session start and end and execute a procedure in the Global.asa file. ASP can also detect both the first use of an application and when it is no longer in use;
it will look to the Global.asa file for procedures in both these cases.
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT=Server>
Application("aiUserCount") = 0
Application("aiUserCount") = Application("aiUserCount") +1
Application("aiUserCount") = Application("aiUserCount") –1