Getting Started with asp: Global.asa file Tip usage

Source: Internet
Author: User
Tags count access root directory

First, ASA is the file suffix name, which is the acronym for Active Server application. The Global.asa file can manage two very demanding objects in ASP applications: application, session.

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 file must reside in the root directory of the application. There can be only one Global.asa file per application.

The most common misconception about global.asa files is that it can be used as a stack for general-purpose functions and subroutines. Global.asa files can only be used to create references and capture launches of objects, and to end application objects and session objects.

Global.asa files are accessed primarily based on session-level events and are invoked in the following three cases:

1 when the Application_OnStart or Application_OnEnd event is triggered.
2 when the Session_OnStart or Session_OnEnd event is triggered.
3, when referencing an object that is instantiated in a Global.asa file.

the standard file format for Global.asa is as follows:

<script language= "VBScript" runat= "Server" >
Sub Application_OnStart
' Application_OnStart run when any customer first accesses the first page of the application
End Sub
Sub Session_OnStart
' Session_OnStart run when a customer first runs any page in an ASP application
End Sub
Sub Session_OnEnd
' Session_OnEnd run when a client's session times out or quits the application
End Sub
Sub Application_OnEnd
' Application_OnEnd run when the Web server for the site is down
End Sub
</SCRIPT>

First, Session_OnStart

Take a look at the code that controls the user's entry into the page:

1,global.asa (placed under the root directory of the virtual directory being debugged)

<script language= "VBScript" runat= "Server" >
Sub Session_OnStart ' As long as the user first login to this site, you will jump to the home page
Response.Redirect ("http://www.webjx.com/")
End Sub
</SCRIPT>

Then debug any files under the current virtual directory, and you'll notice that all the pages are jumping http://www.webjx.com/<
Through this "forced into a page" example, you can imagine that when the home page needs to be attention is very necessary.

The following is an example of an "online number" to continue to observe the Session_OnStart and Session_OnEnd events

Second, Session_OnEnd

2,global.asa (placed under the root directory of the virtual directory being debugged)

<script Language=vbscript runat=server>
Sub Application_OnStart ' initial value is 0
Application ("OnLine") = 0
End Sub
Sub Session_OnStart ' A user access to count plus 1
Application.Lock
Application ("online") = Application ("online") + 1
Application.UnLock
End Sub
Sub Session_OnEnd ' The end of a user process, the count minus 1 (p.s. If the event program is not available, then the page access program is executed.) )
Application.Lock
Application ("online") = Application ("online")-1
Application.UnLock
End Sub
</SCRIPT>

Total 3 page: previous 1 [2] [3] Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.