Sideway
output.to from Sideway
Draft for Information Only

Content

ASP Miscellaneous Features
  ASP Global.asa
     Possible Syntax:
     Parameters:
    Remarks:
   ASP built-in object events
     Application Event:
     Possible Syntax:
     Session Event:
     Possible Syntax:
   OBJECT declarations
     Syntax:
     Parameter:
     Remarks:
   TypeLibrary declarations
     Syntax:
     Parameter:
    Remarks:
   #include directive
   Syntax:
   Attributes:
   Parameters:
   Remarks:

ASP Miscellaneous Features

Besides the feature of directives, ASP technology also provides extra features for the development of the ASP application.

ASP Global.asa

In order to enhance the flexibility of using ASP for web application design, ASP supports an optional file, Global.asa as the global file of an active server application. The optional file must be named Global.asa. Each application can only have one Global.asa file which should be stored in the same root directory of the application. The Global.asa file is not a start page of an application. A Global.asa file is an initial setup of an application in application and session scope before the response of an application to the client. The Global.asa file only run once and must be requested by an ASP page of the application. When an ASP page is requested, the server automatically processes the Global.asa file at the root directory of the application if the Global.asa file has not yet run before. In general, the Global.asa file is not used as a start page for response content to client since the Global.asa file only run once. However, the Global.asa file can be used to store information of events and objects that is used globally by the application as the Global.asa file run before any ASP page of the application. Therefore, the Global.asa file is usually a file of script command to specify event scripts and to declare objects that to be used in the application globally with either session or application scope. Unlike in-line script in an ASP file, the script in Global.asa file usually run once per application or once per session only. Typical elements of a Global.asa file are

  • server-side <SCRIPT> blocks
  • ASP built-in object events:
    • Application_OnStart
    • Application_OnEnd
    • Session_OnStart
    • Session_OnEnd
  • OBJECT declarations
  • TypeLibrary declarations
  • #include directive
Possible Syntax:

<!--METADATA TYPE="TYPELIB" FILE=filename UUID=typelibuuid version= majorversionnumber.minorversionnumber LCID=localeid
-->
<OBJECT RUNAT="SERVER" SCOPE="scope" ID=identifier  {PROGID=progID |CLASSID=classID }>
...
</OBJECT>  
<LANGUAGE=language name RUNAT="SERVER">
Sub Application_OnStart()
...
subprocedure
...
</SCRIPT>
...
<!--#include file|virtual=file name-->
...
<LANGUAGE=language name RUNAT="SERVER">
...
end sub
</SCRIPT>

<LANGUAGE=language name RUNAT="SERVER">
Sub Application_OnEnd
...
End Sub

Sub Session_OnStart
...
End Sub
 
Sub Session_OnEnd
...
End Sub

Sub subprocedure
...
End Sub
</SCRIPT>

Parameters:

language name

The parameter "language name" is the name of the supported scripting language used in the script blocks and is enclosed by quotation marks (" ").

Remarks:

Each ASP application can have only one application in the root directory of the application. The default web site is usually a default application of the web root directory.

The ASP script block with delimiters "<%" and "%>" are not supported within the Global.asa. Only server-side <SCRIPT> blocks are allowed in both the Global.asa file and the #include file. The scripting languages that used in the Global.asa file can be any supported scripting language. Multiple <SCRIPT> blocks of the same scripting language can be combined into one single <SCRIPT> block inside a single set of <SCRIPT> tags.

 In general, only the four ASP build-in events, Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd, are supported by the Global.asa files. Besides, extended <OBJECT> of session or application scope, <METADATA> of TypeLib, and the #include directive are supported in the Global.asa file. And they are self-contained and can be used outside the <SCRIPT> blocks. All <SCRIPT> commond blocks that are not used by the application or session events and HTML tags in the Global.asa are ignored by the web server.

 All procedures declared in the Global.asa file are only available for the script command with the four ASP build-in events, Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd, of the Global.asa file. Procedures declared in the Global.asa file cannot be called from other ASP files or pages of the ASP application. Common procedures of an application should be saved in a separated ASP file so that common pocedures are available for other ASP files through the using of Server.Transfer, ServerExecute, or #include directive etc.

Procedures declared in the Global.asa file can be called only from one or more of the scripts associated with the Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd events. They are not available to the ASP pages in the ASP-based application. To share procedures across an application, you can declare the procedures in a separate ASP file, and then use Server.Transfer Method and Server.Execute Method. You can also use server-side include (SSI) statements to include the file in the ASP pages that call the procedures.

The Global.asa file run once only for each application, the script of the Global.asa file can not refreshed directly through the request of an ASP page of the application. The Application_OnStart and Session_OnStart events of Global.asa file will only be reran again by refreshing the file, triggering the events again, or restarting the application. However, the Global.asa file will not be refreshed immediately after triggering. Instead, the application can only be stopped by server after all current requests have been completed. The sever first deletes all the completed active sessions, and then processes the Session_OnEnd event for each deleted sessions. After the completion of the Session_OnEnd event for all deleted sessions, the server begins to end the application by calling the Application_OnEnd event. The compiled code of the Global.asa will be deleted. The Global.asa file is then recompiled for the subsequent ASP page request of the application. A new request will rerun the application again and create a new session to trigger the  Application_OnStart and Session_OnStart events of Global.asa file accordingly.

ASP built-in object events

One of the major function of the Global.asa file is used to response the events of an ASP application at the beginning or end of an application or a session. The four ASP build-in events supported by the Global.asa files are Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd. The sub procedure of the same name will be triggered by the corresponding event of the ASP application accordingly.

Application Event:

An ASP application is formed by a collection of files in the root directory of an application and all the subdirectories of the root directory. An ASP application is started by the request of a ASP file in the ASP application. And the Global.asa file of the application will then be executed before processing the requested ASP file. Usually, the application will be ended until the server is being shut down. There are two important events, Application_OnStart and Application_OnEnd, in running an ASP application. When the ASP application starts, once the Global.asa file is loaded and executed, the server will look for the Application_OnStart function in the Global.asa file and then processes the Application_OnStart function. And before the ASP application ends and be destroyed, the server will look for the Application_OnEnd function in the Global.asa file and then processes the Application_OnEnd function.

Possible Syntax:

<LANGUAGE=language name RUNAT="SERVER">
Sub Application_OnStart()
...
end sub

Sub Application_OnEnd
...
End Sub
</SCRIPT>

Session Event:

An ASP session can be considered as a temporary trace between the client user and the application of the web server. The web server user will create a session for each client user without a session identifier, so that the user can jumps between pages in the application with only one single session identifier. The session creation is enabled by default, if session tracking in not necessary, session can be disable by the @ENABLESESSIONSTATE directive. When the requested application is available, the session of the requested ASP page in the application starts. If the client user does not have a session, the web server create a session for the client user. The session will be ended either the time out of session or abandoned by the  time. There are two important events, Sesson_OnStart and Session_OnEnd, in the session of a client user navigating an ASP application. When an session of a client starts, once the Global.asa file is loaded and executed, the server will look for the Session_OnStart function in the Global.asa file and then processes the Session_OnStart function. And before the session of a client user ends and be destroyed, the server will look for the Session_OnEnd function in the Global.asa file and then processes the Session_OnEnd function.

Possible Syntax:

<LANGUAGE=language name RUNAT="SERVER">
Sub Session_OnStart
...
End Sub
 
Sub Session_OnEnd
...
End Sub
</SCRIPT>

OBJECT declarations

In the Global.asa file, objects can be declared by the extended <OBJECT> tag. The declared objects should be specified in either application or session scrope by the "SCOPE" attribute.

In order to save resources of the web server, the objects declared in the Global.asa file will not created by web server until the object is called during processing the script. Besides, as the object is only declared by the <OBJECT> tag in the Global.asa file and the object is not created, the OnStartPage and OnEndPage method will not be called by the server until the object is called by script.

Syntax:

<OBJECT RUNAT=SERVER SCOPE=scope ID=identifier { PROGID=progid| CLASSID=classid}>
...
</object>

Parameter:

scope

The parameter "scope" is used to specify the scope of the object. The parameter "scope" used in the Global.asa file can be either "Application" or "Session". For example, SCOPE=application, or SCOPE=session.

identifier

The parameter "identifier" is used to specify the name of the object instance.

progid

The parameter "progid" is used to specify the name of program identifier associated with the class identifier of the object. The format of progid is [Vendor.]Component[.Version] and is enclosed by quotation marks (" ").

classid

The parameter "classid" is used to specify the name of the unique identifier associated with the COM class object and is enclosed by quotation marks (" ").

Remarks:

The <OBJECT> tag is a self-contained tag and can be used outside of the <SCRIPT> tag.

Since the associated name of the object must be declared in the <OBJECT> tag, either PROGID or CLASSID should be specified.

TypeLibrary declarations

A type library is an essential part of an object or a component. Necessary information about objects and types supported by a COM component for the compiler can be stored in a type library file. For example, the assigning of constants for a COM component or declaring of data types used in a COM object can be defined by a type library. In the Global.asa file, type library can also be declared so that the type library can be refered by any ASP files within the application scrop.

Syntax:

<!-- METADATA TYPE="TypeLib" FILE="file" UUID="typelibraryuuid" VERSION="majorversionnumber.minorversionnumber" LCID="localeid" -->

Parameter:

file

The parameter "file" is used to specify the absolute path of the type library and is enclosed by quotation marks (" ").

typelibraryuuid

The parameter "typelibraryuuid" is used to specify the universally unique identifier of the type library and is enclosed by quotation marks (" ").

majorversionnumber

The parameter "majorversionnumber" is an optional parameter used to specify the major version number of the type library and is enclosed by quotation marks (" "). If the requested version is not found, the most recent version is used.

minorversionnumber

The parameter "minorversionnumber" is an optional parameter used to specify the minor version number of the type library and is enclosed by quotation marks (" "). If the requested version is not found, the most recent version is used.

localeid

The parameter "localeid" is an optional parameter used to specify the locale identifier for the type library and is enclosed by quotation marks (" ").

Remarks:

The <METADATA> tags is a self-contained tag and can be placed anywhere inside of the Global.asa file, including both inside and outside the <SCRIPT> tags. However, as the type library is to be refered by any ASP files within the application scrop, the <METADATA> tags are usually located at the top of the Global.asa file.

Either FILE or UUID should be specified. If both FILE and UUID are specified, then FILE is the name used to identify the type library. In order to avoid ambiguous when using constant defined by type library, the name of library name can be used as the prefix of the constant to reduce ambiguousness. For example, ADODB.adErrItemNotFound.

If the locale identifier for the type library is not specified, then the default locale identifier for the system is used or  the locale identifier for the Type Library is set to 0 when the system locale identifier cannot be used.

Besides, the optional STARTSPAN and ENDSPAN keywords in the Global.asa file created by Microsoft Visual InterDev will be ignored by the Internet Information Services (IIS) web server.

#include directive

Server Side Include can also be used to include file by the #include directive for the Global.asa file. This feature allows some common scripts to be saved as seperated files which can be reused by other ASP pages also.

Syntax:

<!--#include file|virtual=file name -->

Attributes:

file: The "file" keyword implies the usage of a relative path began with the file directory that contains the including file named with the "file name" parameter.

virtual: The "virtual" keyword implies the usage of a virtual path began with the virtual directory that contains the including file named with the "file name" parameter.

Parameters:

file name

The parameter "lfile name" is the partial location of the full path that contains the including file which is either relative to folder directory or refered to the virtual folder and is enclosed by quotation marks (" ").

Remarks:

Both the constraints on the #include directive and the Global.asa file are also applied to the scripting of the included file.


©sideway

ID: 121200008 Last Updated: 1/4/2013 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019