An ASP application is a term that generally refers to a grouping of several ASP files that interact with the web visitor. The Application object can be used to
store and access variables from any page, by any visitor. It is similar to the Session object, except that all users share the one application
object. Session objects are unique to each visitor.
The data that is stored in the Application object can be accessed from any page as well as modified/updated from any page. The updated changes are accessible by all
of your visitors. While this is not meant as a replacement for storing data in a database, the Session and Application object is helpful when storing data temporarily about
the users on your site. The Application Object's collections, methods, and events are as follows:
|Contents||Contains all the items appended to the session through a script command|
|StaticObjects||Contains all the objects appended to the session with the HTML <object> element (i.e. in global.asa)|
|Contents.Remove||Deletes an item from the Contents collection|
|Contents.RemoveAll()||Deletes all items from the Contents collection|
|Lock||Prevents the ability from modifying the variables in the Application object|
|Unlock||Re-enables the ability to modify the variables in the Application object|
|Application_OnStart||Occurs when the web application begins.|
|Application_OnEnd||Occurs when the web application ends.|
Store and Retrieve Session Variables
The most common uses for the session object are to store and retrieve information. You create and/or modify session variable information by specifying the variable name within quotes. If you assign string data to the session, encapsulate that
data in quotes as well. If you want to assign numeric data, quotes are not needed.
Remove Session Variables
You can easily remove one variable from the Contents collection or all of the variables using one command. Use either the Remove or RemoveAll method.
In this next example, we can use the Application_OnStart and Application_OnEnd events (defined in the Global.asa file) to maintain a count of the active users accessing our web server.
<script language="vbscript" runat="server">
Application("users") = 0
Application("subtotal") = 0
Application("total") = 0
Application("total") = Application("subtotal")
Application("users") = Application("users") + 1
Application("subtotal") = Application("subtotal") + 1
Application("users") = Application("users") - 1
In your ASP page...
Response.Write("There are " & Application("users") & " users online.")
Recommended Books & Training Resources