ASP global. Asa file reference

Source: Internet
Author: User
The global. Asa file is an optional file in which you can specify event scripts and declare objects with sessions and application scopes. Content of this file
It is used to store event information and objects globally used by applications. The file name must be global. Asa and must be stored in the Application
In the root directory. Each application can have only one global. Asa file.

The global. Asa file can only contain the following content:

1. Application events

2. session events

3. <Object> Declaration

Typelibrary statement
If the included script is not encapsulated with the <SCRIPT> flag, or the defined object does not have a session or application scope, the server returns an error. The server ignores the marked
Scripts recorded but not used by applications or session events, and HTML statements in files.

You can use any language that supports scripts to write scripts contained in the Global. Asa file. If multiple events use the same scripting language, they can be organized in a group
<SCRIPT> tag.

When you save the changes made to the Global. Asa file, the server stops processing all requests of the current application before the global. Asa file is re-compiled.
. During this period, the server rejects other requests and returns an error message, indicating that the application is being restarted and the request cannot be processed.

After all your current requests are processed, the server calls the session_onend event for each session, deletes all active sessions, and calls
The application_onend event closes the application and compiles the global. Asa file. Next, your request starts the application and creates a new session.
Send application_onstart and session_onstart events.

However, saving the changes to the files contained in the Global. Asa file does not allow the server to recompile global. Asa. To allow the server to identify changes to include files,
You must save the global. Asa file.

The process declared in the global. Asa file can only be one or more processes with application_onstart, application_onend, session_onstart, and
Session_onend event-related scripts. ASP pages in ASP-based applications are unavailable.

To share the process between applications, you can declare these processes in a separate file, and then use the server-side include (SSI) statement to include the file in the call process.
. Generally, the file name extension must be. Inc.

An ASP-based application consists of all files in its root directory and Its subdirectories. The application is started when the user opens a web page of the application for the first time.
It is terminated when the server is disabled. The application has two events: application_onstart event and application_onend event.

You can specify scripts for these events in the global. Asa file. When an application is started, the server searches for and processes the application in the global. Asa file.
Application_onstart event script. When the application is terminated, the server processes the application_onend event script.

1. application_onstart
The application_onstart event occurs before the first session (session_onstart event) is created. Only application and server built-in
Objects are available. Referencing the session, request, or response object in the application_onstart event script will cause an error.

Syntax
<Script language = scriptlanguage runat = Server> sub application_onstart... end sub

</SCRIPT>

Parameters
Scriptlanguage
Specifies the script language used to write event scripts. It can be any language that supports scripting, such as VB script or JScript. If multiple events use the same
Script language, which can be organized under a <SCRIPT> tag.

2. application_onend
The application_onend event occurs after the session_onend event when the application exits. Only the application and server built-in objects are available.

Syntax
<Script language = scriptlanguage runat = Server> sub application_onend... end sub

</SCRIPT>

Parameters
Scriptlanguage
Specifies the scripting language used to write event scripts. It can be any language that supports scripts, such as VBScript or JScript. If multiple events use the same
A scripting language that organizes them into a set of <SCRIPT> labels.
Note
You cannot call the mappath method in the application_onend script.

When a user without a session opens a web page in the application, the web server automatically creates a session. When the server times out or calls the abandon method
The session will be terminated.

A session has two events: the session_onstart event and the session_onend event.

You can specify scripts for these two events in the Global File global. Asa. When the session starts, the server looks for and processes it in the global. Asa file.
Session_onstart event script. The script will be processed before processing the web page of the user request. When the session ends, the server will process the session_onend event.
Script.

1. session_onstart
Session_onstart event occurs when the server creates a new session. The server processes the script before executing the request page. Session_onstart event is set
The best time for variables in the session, because they are set before accessing any page. All built-in objects (application, objectcontext, request,
Response, server, and session) can be used and referenced in the session_onstart event script.

Syntax
<Script language = scriptlanguage runat = Server> sub session_onstart... end sub

</SCRIPT>

Parameters
Scriptlanguage
Specifies the scripting language used to write event scripts. It can be any language that supports scripts, such as VBScript or JScript. If multiple events use the same
A scripting language that organizes them into a set of <SCRIPT> labels.
Example
Although the session object remains unchanged when the session_onstart event contains a redirect or end method call, the server stops processing the event.
The script in the global. Asa file that triggers the session_onstart event.

For example, to ensure that a session is always started when you open a specific web page, you can call redirect in the session_onstart event.
Method. When a user enters the application, the server creates a session for the user and processes the session_onstart event script. You can include the script in this event.
Check whether the page opened by the user is a startup page. If not, instruct the user to call the response. Redirect method to start the webpage. The demo is as follows.

<SCRIPT runat = server Language = VBScript>
Sub session_onstart
'Make sure that new users start on the correct
'Page of the ASP application.

'Replace the value given to startpage below
'With the virtual path to your application's
'Start page.

Startpage = "/MyApp/starthere. asp"
Currentpage = request. servervariables ("script_name ")

'Do a case-insensitive compare, and if they
'Don't match, send the user to the start page.
If strcomp (currentpage, startpage, 1) Then response. Redirect (startpage) end ifend sub </SCRIPT>
The preceding example can only be run in a browser that supports cookies. Because browsers that do not support Cookies cannot return sessionid cookies
When the web page is retrieved, the server creates a new session. In this way, for each request, the server will process the session_onstart script and redirect the user
Dynamic page. If you want to use the following script, we recommend that you put a notification on the startup page to tell the user that the site requires a browser that supports cookies.

Note
Note that no session_onstart event script is executed after the Redirect method. Therefore, you should call
Redirect method. The demo is as follows.

<Script language = VBScript runat = Server>
Sub session_onstart
'Session Initialization Script
Response. Redirect "http:/Server/APP/starthere. asp"
End sub
</SCRIPT>
In the preceding example, The redirect method hides all text displayed to the client during the execution of the Session Initialization Script.

2. session_onend
The session_onend event occurs when the session is abandoned or timed out. Only application, server, and session objects are available in Built-in server objects.

Syntax
<Script language = scriptlanguage runat = Server> sub session_onend... end sub

</SCRIPT>

Parameters
Scriptlanguage
Specifies the scripting language used to write event scripts. It can be any language that supports scripting, such as VBScript or JScript. If multiple events use the same
A scripting language, which can be organized under a set of <SCRIPT> labels.
Note
The mappath method cannot be called in the session_onend script.

<Object> Declaration
You can create an object with a session or application scope by using the extended <Object> tag in the global. Asa file. The tag is self-contained and
Outside of any <SCRIPT> flag.

Objects declared in the global. Asa file are not created before the server processes and calls the object. In this way, only necessary objects are created to save resources.

The server does not call the onstartpage and onendpage methods for objects created with Application Scope parameters.

Syntax
<Object runat = server scope = scope id = identifier {progid = "progid" | classid = "classid"}>...

</Object>

Parameters
Scope
Specifies the scope of the object. In the global. Asa file, scope is set to session or application.

Identifier
Specifies the name of the object instance.

Progid
A class ID. Both progid and classid must be specified in <Object>. The progid format is [Vendor.] component.
[. Version].

Classid
Specifies the unique identifier of a COM class object. Both progid and classid must be specified in <Object>.
Example
The first example below uses the progid parameter to create an object whose session scope is myconnection. The second example uses the classid parameter.

<Object runat = server scope = session ID = myconnection progid = "ADODB. Connection">
Rem object script
</Object>

<Object runat = server scope = session ID = myconnection classid = "CLSID: 8ad3067a-b3fc-11cf-a560-00a0c9081c21">
Rem object script
</Object>

Note
Objects declared in the global. Asa file can be used by any script in the application. For example, if the following objects are declared.

--- Global. Asa ---
<Object runat = server scope = session ID = myad progid = "mswc. adrotator">
</Object>

The myad object can be referenced from any page of the application:

--- Some. asp ---
<% = Myad. getadvertisement ("/ADS/adrot.txt") %>

Typelibrary statement

ActiveX components often describe constants supported by this component in the Type Library. A Type Library is a file that contains information about the objects and types supported by ActiveX components.
. If your web application depends on ActiveX objects that have already been declared in the Type Library, you can declare the type in the global. Asa file. This
After the sample is done, you can reference the data types that have been declared in the Type Library from any script within the application scope.

For more information about using constants in ASP, see "using variables and constants ".

Syntax
<! -- Metadata type = "typelib"
File = "file"
UUID = "typelibraryuuid"
Version = "majorversionnumber. minorversionnumber"
Lcid = "localeid"
-->
Parameters
File
The absolute path of the Type Library. If this parameter and typelibraryuuid are provided, file is used to identify the Type Library. File parameters and
The typelibraryuuid parameter is required.

Typelibraryuuid
Unique identifier of a Type Library. Both the file parameter and the typelibraryuuid parameter are required.

Majorversionnumber
Select a version. If the required version cannot be found, an error is returned. This parameter is optional.

Minorversionnumber
Select a version. If the required version cannot be found, an error is returned. This parameter is optional.

Localeid
Field Identification, used for Type Library. If no field is found, an error is returned. This parameter is optional.
Error Message
The server can return the following error messages.

Error description
The Type Library specified by ASP 0222 is invalid. The metadata tag contains an invalid type library.
The Type Library cannot be found in ASP 0223. The Type Library specified in metadata does not match the registry key.
ASP 0224 Type Library cannot be loaded. ASP cannot load the specified type library in the metadata tag.
ASP 0225 type libraries cannot overlap. ASP cannot create a Type Library wrapper object from the Type Library specified in the metadata tag.

Note
It is best to write the metadata mark at the beginning of the global. Asa file. However, both internal and external script tags can appear in global. Asa.
Any location in the file.

By adding the name of the Type Library to the beginning of the constant, you can avoid ambiguous reference to the constant. For example, the ratio of ADODB. aderritemnotfound
Aderritemnotfound is clearer.

If you use Microsoft Visual InterDev to create the global. Asa file, the metadata tag contains the optional startspan and endspan
Key word. IIS ignores these two keywords.

Example
In the following example, mycomponent is written in Visual Basic 5.0. Mycomponent uses the following statement to define the constant myerror.

Public const myerror = "you are not using mycomponent correctly ."

The Type Library is included in mycomponent. Lib. This file is installed in the following directory.

C:/mycomponent

The following metadata tag is contained in the Global. Asa file of the MyApp application. This example uses the optional startspan and endspan tags. While
IIS does not need these two tags.

<! -- Metadata type = "typelib"
File = "mycomponent. lib"
-->

Now, any ASP in the MyApp contains the following script:

<%
Dim myvar
Set myvar = server. Createobject ("mycomponent. myclass ")
Currentreturn = myvar. mymethod
If currentreturn = false
Response. Write (myerror)
End if
%>

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.