ASP 3.0 Advanced Programming (eight)

Source: Internet
Author: User
Tags arrays object character set include numeric value variables variable access
Programming | Advanced 3.3 ASP's application objects and session objects
This chapter has discussed two ASP objects: The Application object and the Session object, thus being able to access the collections, methods, properties, and events provided by application objects and sessions objects. 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.
Figure 3-12 (Figure 1-20) gives the user's request and the distribution of the server's response in the session. All sessions are in an ASP application.

Figure 3-12 ASP Object relationships

3.3.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 shown in table 3-3:
Table 3-3 the collection and description of application objects
Collection
Description

Contents
There is not a collection of all the variables (and their values) that are stored in the Application object, as defined by the <OBJECT> element. 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, using the <OBJECT> element definition

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. Methods and instructions are shown in table 3-4:
The method and description of table 3-4 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 table 3-5:
Table 3-5 Events and descriptions of 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


3.3.2 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 table 3-6:
Table 3-6 the collection and description of Session objects
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 <OBJECT> 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 by using the <OBJECT> element

2. Attributes of the Session object
The Session object provides four properties. These properties and descriptions are shown in table 3-7:
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 ' £ '. 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 <%...%>, taking 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 table 3-8:
Table 3-8 the method and description of the 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


3.3.3 Use App



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.