ASP 3.0 Advanced Programming (IX)

Source: Internet
Author: User
Tags array object end iis processing instruction variable root directory
Programming | Advanced 2. Creating a Variant array
The method of creating and using a Variant array to store values in the session and application objects is not currently discussed, and is discussed here as a very useful technique. As already seen, a Variant data type can contain an array, not just a value.
An array stores only a long line of binary values in a contiguous area of memory in a specified order. To schedule a variant, you need to point to the first item and give information about the size and structure, and the scripting engine can do the rest.
You can create a one-dimensional, two-dimensional, or multidimensional array in a Variant variable, and then assign the array to a variable in an application layer or user session layer, and make sure that the entire array is available in the appropriate place. The following code demonstrates a simple use technique for one-dimensional arrays:
Dim Vararray (3)
Vararray (0) = "This is a"
Vararray (1) = "Variant array"
Vararray (2) = "stored in"
Vararray (3) = "Session Object"
Session ("Variant_array") = Vararray
3. When the application and session starts and ends
This is mentioned in the introduction of ASP applications and how the session works. Outlined below in the most basic terms:
· Starts the application when the first user requests an ASP page of a user-defined virtual application within the scope of the application (that is, the default root of the Web site), or within a subdirectory of the Web site. Occurs before any user session is started.
· When any user requests an ASP page in the default application or a virtual application for the first time, start a session (if there is no active session).
· The session ends when the user does not download an ASP page within the timeout period specified by the session. The timeout can be set by using the Session.Timeout property in script code, either individually in the Properties dialog box, or through the IIS: Partial modification of the default values in the IIS metabase in Active Directory. When a Web page that calls the Session.Abandon method completes execution, the session also ends.
· After the end of the last active session in an application, the application ends immediately.
4. ASP processing Instructions
As seen in chapter 1th, you can add a single processing instruction to an ASP page. A processing instruction can contain more than one entry as needed. The keywords and their descriptions that you can use in statements are as shown in table 3-10:
Table 3-10 ASP directive keyword and description
Directive key word
Description

Language= "Language_name"
Sets the default scripting language for this page, such as: <% @ language= "VBScript"%>

Enablesessionstate= "True" | " Fasle "
Prevents a cookie from a session from being sent to the browser when set to True, so no new session object will be created and the contents of any existing sessions will no longer be available

Codepage= "Code_page"
Sets the code page for the page, such as <% @CODEPAGE = "1252"%>

Lcid= "Locale_identifier"
Sets the location identifier for the page, such as <% @LCID = "2057"%>

transaction= "Transaction_type"
Indicates that the Web page file is running in a transactional environment. Valid values are:
"Required": if there is already a transaction available, the script will run in it, and if there are no transactions available, start a new transaction.
"Requires_new": The script Initializes a new transaction.
"Supported": If a transaction is already available, the script will run in it, and a new transaction is not started.
"not_supported": script will not run in any existing transactions, and does not initialize a new transaction.
Details of the transaction are presented in chapter 18th.

Only one processing instruction can be allowed on a Web page and should be placed on the first line. More than one such entry can be included in the processing instruction, but must be delimited by a space, with no spaces at either end of the equation, for example:
<% @LANGUAGE = "VBScript" codepage= "1252" lcid= "2057"%>

3.3.4 Active ASP Application Object
We provide some simple Web pages that demonstrate the use of the ASP application and session objects in the process. In order to work properly, they must be placed inside a virtual application on the server, and the provided global.asa files are placed in the root directory of the application. The easiest way to do this is to place the Global.asa file in the root directory of the default Web site (c:/inetpub/wwwroot by default).
Renaming any existing Global.asa file is a good way to recover the file later.
All of the examples in this book can be obtained from our web site, and in the CHAPTER03 subdirectory of the example are all the remaining sample pages in this chapter.
In the CHAPTER03 subdirectory, the Default.asp Web page is a simple menu that allows you to run the application and session sample pages, as shown in Figure 3-13:

Figure 3-13 default.asp run Screen
1. Display the contents of the Application collection
Click the first link to open the Application Object sample page named Show_application.asp. It shows the contents of the current Application object for the virtual application, as shown in Figure 3-14:

Figure 3-14 The content screen of the Application object
Note that the Aspcounter object is a member of the StaticObjects collection (defined by the <OBJECT> element), but the remainder (instantiated by Server.CreateObject) is a member of the contents collection.
You can see the values that you put into these collections using the Global.asa example page, which you've seen earlier:
<!--Declare instance of the Aspcounter component with
Application-level Scope//-->
<object id= "Aspcounter" runat= "Server" scope= "Applicatoin"
Progid= "MSWC. Counters ">
</OBJECT>
...
...
<script language= "VBScript" runat= "Server" >
Sub Application_OnStart ()
' Create An instance of a ADO Connection with application-level scope
Set application ("adoconnection") = Server.CreateObject ("ADODB. Connection ")
Dim Vararray (3) ' Create a Variant array and fill it
Vararray (0) = "This is a"
Vararray (1) = "Variant array"
Vararray (2) = "stored in"
Vararray (3) = "Application Object"
Application ("Variant_array") = Vararray ' Store it in THD application
Application ("start_time") = CStr (now) ' Store the Date/time as a string
Application ("visit_count") = 0 ' Set counter variable to zero
End Sub
...
...
</SCRIPT>
(1) Traversing the code of the Contents collection
To traverse the Contents collection, you can use a For each ... Next structure. In the collection



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.