Get to know the global. Asa File

Source: Internet
Author: User
1. role.
The global. Asa file is mainly used for data sharing and multithreading of programs under the site or virtual directory.
2. content. In global. Asa, you can declare application events and session events, and declare some objects in the session range or application range.
Global. Asa can only contain the following content:
1. Application Event
2. session events
3. Object Declaration
4. typelibrary statement
3. Use.
Each site or virtual directory can have a global. Asa file. This file is generally stored in the root directory of the site or virtual directory.
For example, suppose we have created the site mysite, if you want to make global. asa works for all ASP programs under this site, so, global. the ASA should be stored in "/". Suppose we have created a virtual directory demo under the root directory of the site, and we can place a global directory in the demo. to specify a global for the ASP program under this virtual directory. asa.
4. sample code.
The following is an online statistics on the number of people using the application and Session Object events in global. Asa.

<Script language = "VBScript" runat = "server">
Sub application_onstart
Application ("activeusers") = 0
End sub
Sub session_onstart
Session. Timeout = 20
Application. Lock
Application ("activeusers") = Application ("activeusers") + 1
Application. Unlock
End sub
Sub session_onend
Application. Lock
Application ("activeusers") = Application ("activeusers")-1
Application. Unlock
End sub
</SCRIPT>
Note:
1. Multiple global. Asa may exist at the same time, and they are distributed in different virtual directories.
2. If you specify global. ASA for the web program under a virtual directory, the global. Asa under the root directory of the site will not work for ASP under this virtual path.
3. Global. ASA is an inherent file name. It cannot change any letter, but is case insensitive.
4. A web program under a virtual directory can have only one global. asa
5. Global. ASA is invisible to users and does not output any data during client rendering.

Note
Because Global. Asa can obtain application and session event occurrence and stop notifications, this function is very effective and usually used in online display, access count, and chat rooms.
Note

In this example, the lock and Unlock methods of the Application object are used, as well as the onstart event of the application, the onstart and onend events of the session.
Lock the application object to prevent any other scripts from accessing or modifying the application until the unlock method is called.
Unlock unlocks the application object.
Application_onstart is triggered when the first visitor of the application accesses any page in the application.
Session_onstart is triggered when a visitor first requests a page in the application.
Session_onend is triggered when the session times out.
Related Questions
How to clear the specified session Value
In general, simply set the value of this session to null. For example:

S ession ("Demo") = ""

Of course, you can also achieve the same goal by clearing all sessions, but it is not recommended to do so. For example:

Session. Abandon

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.