Name

OnStart — Application_OnStart

Synopsis

The Application_OnStart event is triggered when the first client request is received. Application_OnStart is called only once per application. The code for this event procedure resides in the GLOBAL.ASA file and is processed before any other code or object instantiation in the file.

Parameters

None

Example

' <<<<<<<<<<<<<<< FROM GLOBAL.ASA >>>>>>>>>>>>>>>>>>
' This code resides in the GLOBAL.ASA file at the
' root of the current application. The following
' procedure is processed only once for the current
' application.
' See Chapter 11 for more details on the GLOBAL.ASA file.

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

' This code will run on the server when
' the application starts.
' This code retrieves the last final user count
' and uses it to initialize an Application
' variable.
Set filsysObj1 = CreateObject("Scripting.FileSystemObject")
Set tsObj1 = filsysObj1.OpenTextFile("c:\usrcount.txt", _
             True)
Application.Contents("AppUserCount") = tsObj1.ReadAll
tsObj1.Close

End Sub 
</SCRIPT> 

' <<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>

Notes

The Application_OnStart event procedure, if it exists, is the first code run on the server for a given Active Server Pages application. For this reason, it is the best place to initialize application-level variables. No other code in your ASP application is guaranteed to run.

Carefully consider the use of application-level variables. Every variable with application scope that you ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.