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 |
ASP's Session Object member overview
This section outlines all members of the session object.
1. A collection of Session objects
The Session object provides two collections that can be used to access variables and objects stored in the user's local conversation space. These collections and descriptions are shown in the following table:
A collection of table session objects and descriptions
Collection |
Description |
Contents |
A collection of all variables and their values stored in this particular session object, and these variables and values are not defined using the element. References that include variant arrays and instances of variant type objects |
StaticObjects |
A collection of all the variables that are stored in this session object, defined by using the element |
2. Attributes of the Session object
The Session object provides four properties. These attributes and descriptions are shown in the following table:
Table 3-7 Properties and descriptions of Session objects
Property |
Description |
CodePage |
Read/write. Integral type. Defines the code page that is used to display the content of a page in a browser. The code page is the numeric value of the character set, and different languages and places may use different code pages. For example, ANSI code page 1252 is used in American English and most European languages. code page 932 for Japanese text |
Lcid |
Read/write. Integral type. Defines the page region identity (LCID) that is sent to the browser. The LCID is an international standard abbreviation that uniquely identifies a region, for example, 2057 defines the currency symbol for the current region as ' &pound; '. The LCID can also be used in statements such as FormatCurrency, as long as there is an optional LCID parameter. The LCID can also be set in the ASP processing instruction <%...%> and takes precedence over the settings in the LCID attribute of the session. A list of ASP processing instructions is provided later in this chapter |
SessionID |
Read-only. Long integral type. Returns the session identifier for this session, which is generated by the server when the session is created. Only within the lifetime of the parent Application object, so a new application can be reused when it is started |
Timeout |
Read/write. Integral type. Defines a time-out period in minutes for this session. If the user does not refresh or request a Web page during the timeout period, the session ends. Can be modified as needed on each Web page. The default value is 10min. The time should be shorter on a site with a high usage rate |
3. Method of Session Object
The Session object allows you to delete the specified value from the user-level session space and terminate the conversation as needed. The method and description of the Seesion object are shown in the following table:
Method and Description of table session object
Method |
Description |
Contents.Remove ("Variable_name") |
To remove a variable named Variable_name from the Session.content collection |
Contents.RemoveAll () |
Remove all variables from the Session.content collection |
Abandon () |
When the execution of the Web page completes, the current user session is terminated and the current sessions object is undone. However, even after calling the method, you can still access the variables of the current session in the page. When the user requests the next page, a new session is started and a new sessions object is created (if present) Note that you cannot delete a variable from the Session.StaticObjects collection during run time. |
4. Event for Session Object
The Session object provides two events that are triggered at startup and end, as shown in table 3-9:
Table 3-9 Events and descriptions of Session objects
Event |
Description |
OnStart |
Triggered when an ASP user session is started, before the Web page that the user requests is executed. Used to initialize variables, create objects, or run other code. |
OnEnd |
Triggered when an ASP user session ends. Starts from the user's last page request to the application, triggering the event if it has exceeded the scheduled session time-out period. When the session ends, cancels all variables in the session. This event is also triggered when an ASP user session is terminated using the Abandon method in code |