session是什么意思|关于session的一些问题

更新时间:2014-07-13    来源:面向对象编程    手机版     字体:

【www.bbyears.com--面向对象编程】

如何取得所有的Session变量?
在程序调试中,有时候需要知道有多少Session变量在使用,她们的值如何?由于Session对象提供一个称为Contents的集合(Collection),我们可以通过For...Each循环来达到目标:
Dim strName, iLoop
For Each strName in Session.Contents
Response.Write strName & " - " & Session.Contents(strName)& "
"
Next
一般情况下,上面的代码可以工作得很好。但当Session变量是一个对象或者数组时,打印的结果就不正确了。
这样我们修改代码如下:
""首先看看有多少Session变量在使用?
Response.Write "There are " & Session.Contents.Count & _
" Session variables

"
Dim strName, iLoop
""使用For Each循环察看Session.Contents
""如果Session变量是一个数组?
If IsArray(Session(strName)) then
""循环打印数组的每一个元素
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
Response.Write strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "
"
Next
Else
""其他情况,就简单打印变量的值
Response.Write strName & " - " & Session.Contents(strName) & "
"
End If
Next
Session变量有时候不能工作,为什么?
有很多可能性:
第一,如果客户端不允许cookie操作,session将失效。因为session是依赖于cookie的。
第二,session有失效时间的设定。缺省的设置是20分钟。你可以这样修改它:Web directory -> Properties -> Virtual directory -> Application settings -> Configuration -> App Options -> Session timeout
或者在ASP中,写上这样的代码:Session.timeout=60 。
第三,session是和具体的Web Application相关的。如果用户从/products/default.asp浏览到/jobs/default.asp,也可能造成session的重新创建。
怎么清除一个不再需要的session变量但不使session失效?
在ASP3.0中:
Session.Contents.Remove "变量名"
可以清除一个变量。
在ASP2.0中:
set session("变量名")=NULL

本文来源:http://www.bbyears.com/jsp/7766.html