In-depth study of Application and Session objects (including global. asa) 3

Source: Internet
Author: User
III. Global. asa
The Application and Session objects of ASP reflect the features that other ASP built-in objects do not have-events. Each visitor accesses the server and triggers an OnStart event (the first visitor simultaneously triggers the OnStart event of the Application and Session, but the Application is prior to the Session ), an OnEnd event is triggered at the end of each guest Session (the OnEnd event of the Application and Session is triggered at the end of the last guest Session, but the Session is prior to the Application ).
OnStart and OnEnd events are generally used to count the number of online users in the virtual community, and modify the online offline status of users. To define these two events, you need to write the code in the Global. asa file and put the file in the root directory of the site (Inetpubwwwroot by default ). In addition, the Application and Session objects stipulate that all ASP built-in objects (Response, Request, Server, Session...) except Application objects cannot be used in OnEnd events. The following is an example of how to count the number of online users in a virtual community to show how to use these two events.
File description:
Global. asa is located in the d: Inetpubwwwroot directory.
Default. asp is located in the d: Inetpubwwwroot Directory. The logon page of the virtual community is displayed.
Login. asp is located in the d: Inetpubwwwroot Directory. It is used to detect the user name and password entered by the user.
Index. asp is located in the d: Inetpubwwwroot directory, the home page of the virtual community
Bbs. mdb is located in the d: Inetpubwwwroot directory, the database that stores user information
Database (ACCESS) structure:
=== Bbs table ===
Id User id, long integer
Name username, text type
Code password, text type
Online Status, yes/no

=== Global. asa ===
<Script LANGUAGE = "VBScript" RUNAT = "Server">
Sub Application_OnStart
Application ("online") = 0
End Sub
Sub Application_OnEnd
Nd Sub
Sub Session_OnStart
End Sub
Sub Session_OnEnd
If session. contents ("pass") then', determine whether it is the user's Session_OnEnd
Application. lock
Application ("online") = application ("online")-1
Application. unlock
End if
End Sub
</Script>
====================
=== Login. asp ===
... 'Password verification, connect to the database, and check whether the user name and password entered by the user are correct

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.