YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.***w3.org/TR/REC-html40/loose.dtd">
asp入门教程:ASP 全局变量 Global.asa 文件
Global.asa文件是一个可选文件,可以包含申报的对象,变量和方法,可以通过在每一页的ASP应用程序。
-------------------------------------------------- ------------------------------
Global.asa文件
Global.asa文件是一个可选文件,可以包含申报的对象,变量和方法,可以通过在每一页的ASP应用程序。所有有效的浏览器的脚本( JavaScript中,脚本语言, PerlScript等) ,可用于在Global.asa中。
Global.asa文件只能包含以下内容:
应用事件
会议活动
声明
TypeLibrary声明
在#包括指令
注: Global.asa文件必须存放在根目录中的ASP应用程序,每个应用程序只能有一个Global.asa文件。
-------------------------------------------------- ------------------------------
Global.asa中的活动
Global.asa中你可以告诉应用和会议的物体时该怎么做的应用/会议开始和该怎么做时,应用/会议的目的。该代码,这是放置在事件处理程序。 Global.asa文件可以包含四种类型的活动:
Application_OnStart -这一事件发生时,第一个用户要求的第一页从A SP应用程序。此事件发生后, Web服务器重新启动或之后的Global.asa文件编辑。该“ Session_OnStart ”事件发生后立即这一事件。
Session_OnStart -此事件发生每当一个新的用户要求他或她的第一页中的A SP应用程序。
Session_OnEnd -此事件发生每当用户结束了会议。用户一次会议结束后,页面已经没有要求用户指定的时间(默认情况下,这是20分钟) 。
Application_OnEnd -此事件发生后的最后一个用户已经结束了会议。通常情况下,此事件发生时, Web服务器停止。这个程序是用来设置清理后停止的应用,如删除记录或写入资料,文本文件。
阿Global.asa文件可能看起来就像这样:
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
注意:由于我们不能使用ASP脚本分隔“ ( 因素。
-------------------------------------------------- ------------------------------
声明
这是有可能创造物体的会议或适用范围Global.asa中使用标记。
注: 标记应以外的
object runat="server" scope="scope" id="id" {progid="progID"|classid="classID"}> ....
| Parameter | Description |
|---|---|
| scope | Sets the scope of the object (either Session or Application) |
| id | Specifies a unique id for the object |
| ProgID | An id associated with a class id. The format for ProgID is [Vendor.]Component[.Version] Either ProgID or ClassID must be specified. |
| ClassID | Specifies a unique id for a COM class object. Either ProgID or ClassID must be specified |
范例
第一个例子创建了一个对象范围的会议名为“ MyAd ”使用的ProgID参数:
第二个例子创建了一个对象的适用范围命名为“ MyConnection ”使用的ClassID参数:
申报的对象在Global.asa文件可以使用任何脚本的应用程序:
GLOBAL.ASA:
You could reference the object "MyAd" from any page in the ASP application:
SOME .ASP FILE:
TypeLibrary声明
阿TypeLibrary是一个容器的内容DLL文件相应的COM对象。包括呼吁TypeLibrary在Global.asa文件中,常量的COM对象可以访问,错误可以得到更好的报告的ASP代码。如果您的Web应用程序依赖于COM对象已宣布的数据类型的类型库,你可以宣布类型库Global.asa中。
语法
| Parameter | Description |
|---|---|
| file | Specifies an absolute path to a type library.
Either the file parameter or the uuid parameter is required |
| uuid | Specifies a unique identifier for the type library.
Either the file parameter or the uuid parameter is required |
| version | Optional. Used for selecting version. If the requested version is not found, then the most recent version is used |
| lcid | Optional. The locale identifier to be used for the type library |
误差值
该服务器可返回下列其中一个错误讯息:
| Error Code | Description |
|---|---|
| ASP 0222 | Invalid type library specification |
| ASP 0223 | Type library not found |
| ASP 0224 | Type library cannot be loaded |
| ASP 0225 | Type library cannot be wrapped |
注:元数据标签可以出现在Global.asa文件(包括内部和外部
Global.asa中也可以被用来控制页面访问。
下面的例子显示了如何重新每一个新的访问者到另一个网页,在这种情况下,在网页上所谓的“ newpage.asp ” :
您可以包括职能的Global.asa文件。
在下面的例子中的Application_OnStart副程式发生时, Web服务器启动。
然后Application_OnStart副程式呼叫另一个副程式名为“ getcustomers ” 。该“ getcustomers ”
子程序打开一个数据库和检索纪录的“客户”表。该纪录是分配给一个数组,它可以从任何ASP网页查询资料库:
sub Application_OnStart getcustomers end sub
sub getcustomers
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=conn.execute("select name from customers")
Application("customers")=rs.GetRows
rs.Close
conn.Close
end sub
Global.asa中为例
在这个例子中,我们将创建一个Global.asa文件算数的数量目前的访客。
Application_OnStart集的应用程序变量“游客”为0时,服务器启动
副程式的Session_OnStart了一个变数“游客”每当一个新的访问者到达
副程式的Session_OnEnd减去一个“访客”每次这种子程序触发
Global.asa文件:
Sub Application_OnStart
Application("visitors")=0
End Sub
Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub
要显示当前的一些游客在ASP文件:
There are online now!
转载请注明来自