您的位置:首页 > 其它

在.net中获取所有session变量的值

2014-02-26 21:06 197 查看
备用贴:

在程序调试中,有时候需要知道有多少Session变量在使用,她们的值如何?由于Session对象提供一个称为Contents的集合(Collection),我们可以通过For...Each循环来达到目标:

Dim strName, iLoop

For Each strName in Session.Contents

Response.Write strName & " - " & Session.Contents(strName)& "<BR>"

Next

一般情况下,上面的代码可以工作得很好。但当Session变量是一个对象或者数组时,打印的结果就不正确了。

这样我们修改代码如下:

'首先看看有多少Session变量在使用?

Response.Write "There are " & Session.Contents.Count & _

" Session variables<P>"

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) & "<BR>"

Next

Else

  '其他情况,就简单打印变量的值

Response.Write strName & " - " & Session.Contents(strName) & "<BR>"

End If

Next
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: