最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp入门教程:ASP applocation 全局变量与 Global.asa 文件
时间:2022-07-02 22:41:07 编辑:袖梨 来源:一聚教程网
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文件只能包含以下内容:
应用事件
会议活动
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脚本分隔“ ( 因素。
-------------------------------------------------- ------------------------------
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 subsub 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 subGlobal.asa中为例
在这个例子中,我们将创建一个Global.asa文件算数的数量目前的访客。
Application_OnStart集的应用程序变量“游客”为0时,服务器启动
副程式的Session_OnStart了一个变数“游客”每当一个新的访问者到达
副程式的Session_OnEnd减去一个“访客”每次这种子程序触发
Global.asa文件:
Sub Application_OnStart Application("visitors")=0 End SubSub Session_OnStart Application.Lock Application("visitors")=Application("visitors")+1 Application.UnLock End SubSub Session_OnEnd Application.Lock Application("visitors")=Application("visitors")-1 Application.UnLock End Sub要显示当前的一些游客在ASP文件:
There are online now!
转载请注明来自
相关文章
- 口袋斗罗大陆小舞有哪些玩法技巧 09-16
- 逆战未来冰狙击步枪如何组装 09-16
- 如鸢董奉角色怎么样 09-16
- 环外技能怎么进阶 09-16
- 三国群英传策定九州如何发展建筑 09-16
- 三国望神州郭嘉怎么玩 09-16