ASP's Global.asa use instructions _FSO topics

Source: Internet
Author: User
/*-------------------ASP Document reference set-----------------------* *
*--> Author: paramecium
*--> time: 2007-4.28---2007-4.30 (originally a manual written by oneself, now sent here)
*--> Contact: caolvchong@gmail.com
*--> Document Features:
1. Review the ASP, deepen the understanding of ASP structure and the experience of ASP
2. Can be used as an ASP reference, write their own, reference to more convenient

This is part four: Global.asa

/*---------------------------About ASP Components------------------------* *
ASP components are not described, encountered important components (mainly third-party components), such as upload components, and so on, and then specifically
Introduced
/*==============================end==================================*/

* *-----------------------Global.asa-------------------------* *
. ASA is the file suffix name, which is the initials of the active Server application. Global.asa files can be
Managing two very demanding objects in ASP applications: application, Session
Global.asa is an optional file in which program writers can specify event scripts and declare that they have sessions and
The object of the application scope. The contents of this file are not intended to be displayed to the user, but are used to store event information and
An object that is used globally by the application. The file must reside in the root directory of the application. Each application can have only one
A Global.asa file
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 Application_OnStart or Application_OnEnd events are triggered.
2. When Session_OnStart or Session_OnEnd events are 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>

Two examples of Global.asa classics:
1. Forced access to the home page, is if the first visit to the Web site, forced to navigate to the home page method:
<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 ("Home Address")
End Sub
</SCRIPT>

2. Online statistics of the number of Web sites:
<script language= "VBScript" runat= "Server" >
Sub Application_OnStart
' Set the user counter to 0 when the server is turned on
Application ("activeusers") = 0
End Sub

Sub Session_OnStart
' Set the Session object to be valid for 20 minutes (or longer, but longer for server
' The more resources are consumed because the server does not accept a valid time less than 20 minutes, so set less than 20
' The effective time of the minute is invalid '
Session.Timeout = 20
' When starting a session, the user counter plus 1
Application.Lock
Application ("activeusers") = Application ("activeusers") + 1
Application.UnLock
End Sub
  
Sub Session_OnEnd
' User counter minus 1 when ending a session
Application.Lock
Application ("activeusers") = Application ("Activeusers")-1
Application.UnLock
End Sub
</SCRIPT>

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.