Let me tell you how to use the Global.asa file.
What is a Global.asa file? It is actually an optional file where program writers can specify event scripts and declare objects with session and application scopes. The contents of this file are not intended to be displayed to the user, but are used to store event information and objects that are used globally by the application. The name of the file must be global.asa and must reside in the application's root directory. There can be only one Global.asa file per application.
In the Global.asa file, the server returns an error if the included script is not encapsulated with a < script> tag, or the defined object does not have a session or application scope. We can write scripts contained in global.asa files in any language that supports scripting. If multiple events use the same scripting language, they can be organized into a set of < script> tags.
A procedure declared in a Global.asa file can only be invoked from one or more scripts related to Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd events. In ASP pages for ASP-based applications, they are not available. If you want to share procedures between applications, you can declare them in a separate file and then use server-side containment (SSI) statements to include the file in the ASP program that calls the procedure. Typically, an extension of the containing file should be. Inc.
The following is a very standard Global.asa file:
< SCRIPT language= "VBScript" runat= "Server" > ' Session_OnStart run when a customer first runs any page in an ASP application ' Session_OnEnd when a client's session Run ' Application_OnStart when any customer first accesses the home page of the application when a timeout or exit application runs ' Application_OnEnd when the Web server for that site shuts down </script> < SCR IPT language= "VBScript" runat= "Server" > Sub application_onstart visitorcountfilename = Server.MapPath ("/ex2") + "\vi SitCount.txt "Set fileobject = Server.CreateObject (" Scripting.FileSystemObject ") Set out= Fileobject.opentextfile ( Visitorcountfilename, 1, False, False) application ("visitors") = Out.readline Application ("visitorcountfilename") = Vis Itorcountfilename End Sub ' ========================================================= sub Application_OnEnd Set Fileoutobject = Server.CreateObject ("Scripting.FileSystemObject") Set out= fileoutobject.createtextfile (Application ("Visitorcountfilename"), True,false) out.writeline (Application ("visitors")) End Sub ' ============================= ============================sub Session_OnStart SEssion. Timeout = 5 Application ("visitors") = Application ("visitors") + 1 session ("IDs") =session.sessionid End Sub </script
>
In this Global.asa program, the ASP's file access component is involved, which provides methods, properties, and collections for accessing the file system. This will be discussed later in the ASP's components. Here, it plays the role of creating a new file on the server and writing to the file. This is actually an ASP page accessing the Register application's Global file, first when the customer first accesses the application's home page, the procedure Application_OnStart defines a new VisitCount.txt text file under the virtual directory specified on the server. and save the path and content of the file in an application-level variable. When any client accesses any page in an ASP application, the procedure Session_OnStart defines an automatic addition of the value of the application-level variable visitors. In this way, every time a customer visits the page, the variable visitors will automatically add one, to play the role of statistical clicks. Because the value of the variable visitors is stored in system memory, if the server shuts down or restarts, the data stored in the variable is automatically lost, so by defining the procedure Application_OnEnd, the data is written to a previously established text file before the server shuts down or restarts. This ensures that when the server starts again, the Application_OnStart process can read the previous statistics from the VisitCount.txt file.
The above is the entire content of this article, I hope to help you learn.