ASP Tutorial: Simple Learning to master ASP application objects

Source: Internet
Author: User
Tags variables variable
application| Objects | tutorials

A set of ASP files that work together to accomplish a task are called Applications (application). The Application object in ASP is used to bundle these files together.

Application objects

An application on the Web can be a set of ASP files. These ASP files work together to accomplish a task. The Application object in ASP is used to bundle these files together.

The Application object is used to store and access variables from any page, similar to the Session object. The difference is that all users share a Application object, while the session object and the user's relationship are one by one corresponding.

The Application object holds information (such as database connection information) that will be used by many pages in the application. This means that the information can be accessed from any page. It also means that you can change the information somewhere, and then the changes will be automatically reflected on all the pages.

Storing and retrieving application variables

Application variables can be changed by any page in the application.

You can create a application variable like this in "Global.asa":

<script language= "VBScript" runat= "Server" >sub application_onstartapplication ("vartime") = "" Application (" Users ") =1end sub</script>

In the example above, we created two application variables: "Vartime" and "users."

You can access the value of the application variable like this:

There are <%response.write (Application ("users"))%> active connections.

Loop Traversal Contents Set

The contents set contains all the application variables. We can view the variables stored in it by traversing the contents set:

<%dim IFOR each I in application.contents  Response.Write (i & "<br/>") next%>

If you don't know the number of items in the contents set, you can use the Count property:

<%dim Idim jj=application.contents.countfor I=1 to J  Response.Write (Application.Contents (i) & "<br/> ") next%>

Loop Traversal StaticObjects Set

You can iterate through the StaticObjects set to see all the values stored in the Application object:

<%dim IFOR each I in application.staticobjects  Response.Write (i & "<br/>") next%>

Lock and Unlock

We can use the "lock" method to lock an application. When the application is locked, the user cannot change the application variable (except the user who is accessing the application variable). We can also use the "Unlock" method to unlock the application. This method removes the lock on the application variable:

<%application.lock  ' Do some Application object operationsapplication.unlock%>


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.