In-depth study of application and session objects (including Global.asa) 1

Source: Internet
Author: User
Tags root directory
application|session| object with ASP to write virtual community, online shopping and other programs, application and session object plays a pivotal role, the flexibility and reasonable use of these two objects is the key to improve the quality of the program. The following let the author according to their own experience in this area, to you in-depth introduction of the ASP's two built-in objects.

Overview of members of a Application object

Application object members include collections, methods, and events for application objects.

Collection of ⒈application objects

Contents collection: A collection of all variables stored in Applicaiton objects that are not defined using the <OBJECT> element

StaticObjects: A collection of all the variables stored in the Application object, defined using the <OBJECT> element

Example: The following assignment is available in the Default.asp

Application ("a") = "a"

Application ("B") =128

Application ("C") =false

Then there are contents sets

Application.Contents (1) = "A" can also be written as application.contents ("a") = "a"

Application.Contents (2) =128 ' can also be written as application.contents ("B") =128

Application.Contents (3) =false ' can also be written as application.contents ("C") =false

In this article I recommend that you use classes such as Application.Contents ("a") in the call, because this is more intuitive, if the number of words to consider the order of assignment.

Methods of ⒉application objects

Contents.Remove ("Variable name"): Removes the specified variable from the Application.Contents collection

Contents.RemoveAll (): Remove all variables from the Application.Contents collection

Lock (): Locks the Application object so that only the current ASP page can access the content

Unlock (): Unlocking the Application object

Example: In the Default.asp:

Application ("a") = "a"

Application ("B") =128

Application ("C") =false

Response.Write application.contents (1) & "<br>"

Response.Write Application.Contents (2) & "<br>"

Response.Write Application.Contents (3) & "<br>"

Response.Write "after Remove B:"

Application.Contents.Remove ("B")

Response.Write application.contents (1) & "<br>"

Response.Write Application.Contents (2) & "<br>"

Execution results:

A

128

False

After Remove B:

A

False

If you want to delete all the variables in the collection with Application.contents.removeall, the lock and unlock methods are often used in practice, and the reader is more familiar with it.

⒊application Object Events

OnStart: The first time a user accessing a server occurs when a page is first accessed

OnEnd: When the last user's session has ended and the session's OnEnd event has been completed, or the last user accesses the server for a period of time (typically 20 minutes), no one has access to the server.

What you want to define in the OnStart and OnEnd events of the Application object is to write the code in the Global.asa file (for an example below) and place the file in the root directory of the site (typically inetpub\wwwroot\)



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.