热门关键字: excel200 蓝光笔记 pps有图像 excel winrar使 添加水印 輸入法 actionsc
当前位置 : IT 知识库 > 网站建设 > 网络编程 > 正文

解析ASP的Application和Session对象

作者:佚名时间:08-03-23
为了能够正常使用,必须把它们放到服务器上的一个虚拟应用程序内,并且把所提供的global.asa文件放到该应用程序的根目录中。最简单的办法是把global.asa文件放到缺省Web网站的根目录(缺省情况下是C:/InetPub/WWWRoot)中。

  对任何已有的global.asa文件重命名是一个好办法,可以在以后对该文件进行恢复。

  1. 显示Application集合的内容

  ASPCounter对象是StaticObjects集合的一个成员(通过<OBJECT>元素进行定义),但是其余部份(由Server.CreateObject实例化)是Contents集合的成员。

  可以看到使用global.asa例子网页放到这些集合中的值,这在前面已经看到:

<!-- Declare instance of the ASPCounter component with
application-level scope //-->
<OBJECT ID=”ASPCounter” RUNAT=”Server” SCOPE=”Applicatoin”
PROGID=”MSWC.Counters”>
</OBJECT>
...
...
<SCRIPT LANGUAGE=”VBScript” RUNAT=”Server”>
Sub Application_onStart()
‘Create an instance of an ADO Connection with application-level scope
Set Application(“ADOConnection”) = Server.CreateObject(“ADODB.Connection”)
Dim varArray(3) ‘Create a Variant array and fill it
varArray(0) = “This is a”
varArray(1) = “Variant array”
varArray(2) = “stored in the”
varArray(3) = “Application object”
Application(“Variant_Array”) = varArray ‘Store it in thd Application
Application(“Start_Time”) = CStr(Now) ‘Store the date/time as a string
Application(“Visit_Count”) = 0 ‘Set counter variable to zero
End Sub
...
...
</SCRIPT>

  (1) 遍历Contents集合的代码

  为了遍历Contents集合,可使用一个For Each ... Next结构。集合中的每一项可以是一个简单的Variant类型变量、一个Variant数组或者一个对象的引用。因为需要对每种类型的值进行不同的处理,所以就不得不对每一个进行检查来判别其类型。

  在VBScript中可使用VarType函数完成这个工作。这里使用IsObject和IsArray函数代替:

For Each objItem in Application.Contents
If IsObject(Application.Contents(objItem)) Then
Response.Write “Object reference: ‘” & objItem & “’

ElseIf IsArray(Application.Contents(objItem)) Then
Response.Write “Array: ‘” & objItem & “’ contents are:

VarArray = Application.Contents(objItem)
‘Note: the following only works with a one-dimensional array
For intLoop = 0 To UBound(varArray)
Response.Write “ Index(“ & intLoop & “) = “ & _
VarArray(intLoop) & “

Next
Else
Response.Write “Variable: ‘” & objItem & “’ = “ _
& Application.Contents(objItem) & “

End If
Next

 
最新文章
网络编辑用傲游提高工作效率
你在用傲游(Maxthon)的时候有没有体会到它给你的编辑工作带来的便捷呢?以下是我...
PHP技巧:php过滤危险html代码
用PHP过滤html里可能被利用来引入外部危险内容的代码。 有些时候,需要让用户...
相关文章
优化系统设置 让XP快速如飞
虽然XP被微软自称为有史以来最稳定、功能最强大的Windows操作系统,并且运行速度...
打造顶级系统的正确优化方法
现在网友对系统优化已经不再感兴趣了很多是说优化前和优化后都差不多,对速度和...
本站推荐