【转】ASP - Global.asa

The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.
Global.asa文件是一个可选文件,它包括了对对象、变量的声明以及对每个页面应用程序访问方法的声明。

Note: The Global.asa file must be stored in the root directory of the ASP application, and each application can only have one Global.asa file.
注意:Global.asa文件必须被存储在ASP程序文件的根目录中,且每个应用程序文件只能拥有一个Global.asa文件。

The Global.asa file can contain only the following:
Global.asa文件只能包含以下内容:

  • Application events
    Application 事件
  • Session events
    Session 事件
  • <object> declarations  
    <object> 声明
  • TypeLibrary declarations
    TypeLibrary 声明
  • the #include directive
    #include 关键词

Application and Session Events
Application事件和Session事件

In Global.asa you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code for this is placed in event handlers. Note: We do not use <% and %>, to insert scripts in the Global.asa file, we have to put the subroutines inside the HTML <script> tag:
在Global.asa文件当中,你可以在它们开始或结束的时候区别Application和Session这两个对象,这些代码被放置在了事件处理器当中。注意:我们不使用“<%”和“%>”向Global.asa文件中插入脚本,我们需要把子程序放置到HTML<script>标签中。

<script language="vbscript" runat="server">
sub Application_OnStart
  ' some code
end sub
sub Application_OnEnd
  ' some code
end sub
sub Session_OnStart
  ' some code
end sub
sub Session_OnEnd
  ' some code
end sub
</script>

<object> Declarations
<object>声明

It is also possible to create objects with session or application scope in Global.asa by using the <object> tag. Note: The <object> tag should be outside the <script> tag!
我们也可以通过使用Global.asa中的<object>标签建立session和application对象。注意:<object>标签必须写在<script>标签之外

Syntax:
语法:

<object runat="server" scope="scope" id="id"
{progid="progID"|classid="classID"}>
.......
</object>

TypeLibrary Declarations
Typelibrary声明

A TypeLibrary is a container for the contents of a DLL file corresponding to a COM object. By including a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. If your Web application relies on COM objects that have declared data types in type libraries, you can declare the type libraries in Global.asa.
TypeLibrary声明涵盖了所有与COM对象相关的DLL文件的内容。通过呼叫Global.asa文件中的TypeLibrary,可以访问COM对象常量,所有的错误可以通过ASP代码很好的被显示出来。如果你的网络应用程序依赖一些已经在type library中声明了数据类型的COM对象,你也可以在Global.asa文件中声明type libraries。

Syntax:
语法:

 <!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
-->