In the published series we have discussed two ASP objects: The Application object and the session object, thus having access to the collection, methods, properties, and events provided by the Application object and the Sessions object. This section will study these two objects from the perspective of programming.
· When loading an ASP DLL and responding to the first request for an ASP Web page, create the Application object. This object provides a storage place to store variables and objects that are available to all Web pages that are open to all visitors.
· When the visitor first requests an ASP page from the site, create a session object for him and remain valid until the default time-out period (or the timeout period determined by the script). This object provides a storage place to store variables and objects that are available only to pages that the visitor opens during the session's activity.
Relationship
1, ASP's Application Object member overview
This section describes the collection, methods, and events of the Application object (Application object has no attributes). The Session object (with attributes) is described in the next section. You will then continue to explore the tasks accomplished by using these objects and describe in more detail how each member of each object works.
1. Collection of Application objects
The Application object provides two collections that can be used to access variables and objects stored in the global application space. The collection and description are as follows:
The collection and description of table application objects
Collection |
Description |
Contents |
A collection of all the variables (and their values) stored in the Application object that are defined by the element is not used. References that include variant arrays and instances of variant type objects |
StaticObjects |
A collection of all the variables (and their values) that are stored in the Application object, as defined by the element |
2. Methods of Application objects
The Application object method allows you to delete values in the global application space and control concurrent access to variables within that space. Method and description as shown in the following table:
Method and description of table Application Object
Method |
Description |
Contents.Remove ("Variable_name") |
To remove a variable named Variable_name from the Application.content collection |
Contents.RemoveAll () |
Remove all variables from the Application.content collection |
Lock () |
Locks the Application object so that only the current ASP page can access the content. A concurrent operation that ensures that two users are allowed to read and modify this value at the same time does not break the content |
Unlock () |
Unlock an ASP Web page on a Application object |
Note that you cannot delete a variable from the Application.staticobjects collection during run time.
3. Events for application objects
The Application object provides two events that are triggered when it starts and ends, as shown in the following table:
Events and descriptions for table application objects
Event |
Description |
OnStart |
Triggered when ASP starts, before the Web page that the user requests is executed and before any user creates the Session object. For initializing variables, creating objects, or running other code |
OnEnd |
Triggered when an ASP application is finished. Occurs after the last user session has ended and all the code in the OnEnd event of the session has been executed. When it ends, all variables present in the application are canceled |