In ASP, the Global.asa file is an optional file that is generally used to declare application and/or session variables that can be accessed by every page in an ASP
application. The Global.asa file is stored in the root directory of the ASP application. You can only have one Global.asa file.
In Global.asa you can instruct the web server as to what to do when the ASP application starts and ends, as well as when a user session starts and ends.
The start and end events for the application and session are handled by the following four types of events:
This event occurs when the first visitor calls the very first page in an ASP application. This event occurs after the Web server is restarted
or after the Global.asa file is edited. The "Session_OnStart" event occurs immediately after this event.
This event occurs every time a new visitor requests his or her first page in the ASP application.
This event occurs every time a user session ends. The session ends after a timeout period of inactivity. By default, the value is 20 minutes.
This event occurs after the last user session has ended, such as when the web server service has stopped.
Here is an example of how to use the Global.asa file to track the number of online visitors:
<script language="vbscript" runat="server">
Application("users") = 0
Application("subtotal") = 0
Application("total") = 0
Application("total") = Application("subtotal")
Application("users") = Application("users") + 1
Application("subtotal") = Application("subtotal") + 1
Application("users") = Application("users") - 1
Display the number of online users in your ASP page:
<p>There are <% Response.Write(Application("users")) %> online now!</p>
Recommended Books & Training Resources