取得所有的Session变量
来源:互联网 发布:苹果电脑换windows系统 编辑:程序博客网 时间:2024/06/10 08:56
在程序调试中,有时候需要知道有多少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
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
可以清除变量。
在ASP3.0中,
Session.Contents.RemoveAll
可以清除所有的session变量和session.abandon不同,上面的方法都不会使目前的session过期或者无效。
ASP页面顶端的<%@ ENABLESESSIONSTATE=True %>是什么意思?
IIS使用一种叫做Session跟踪的技术,来保证各个Session变量在每个页面是可用的。当用户访问某个ASP页面时候,IIS会首先为这个页面准备好各个Session变量,这当然会带来性能上的影响。(使用Session变量的代价总是很高的!)
如果你有100个页面,而只有5个页面用到了Session,那么,为了整体的性能,你只需要在那5个页面设置:
<%@ ENABLESESSIONSTATE=True %>
而其他页面设置为:
<%@ ENABLESESSIONSTATE=False %>
<SCRIPT type=text/javascript><!--google_ad_client = "pub-1634561494151585";/* 468x60, articlebottom */google_ad_slot = "7716109916";google_ad_width = 468;google_ad_height = 60;//--></SCRIPT><SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript></SCRIPT><SCRIPT> window.google_render_ad(); </SCRIPT>
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
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
可以清除变量。
在ASP3.0中,
Session.Contents.RemoveAll
可以清除所有的session变量和session.abandon不同,上面的方法都不会使目前的session过期或者无效。
ASP页面顶端的<%@ ENABLESESSIONSTATE=True %>是什么意思?
IIS使用一种叫做Session跟踪的技术,来保证各个Session变量在每个页面是可用的。当用户访问某个ASP页面时候,IIS会首先为这个页面准备好各个Session变量,这当然会带来性能上的影响。(使用Session变量的代价总是很高的!)
如果你有100个页面,而只有5个页面用到了Session,那么,为了整体的性能,你只需要在那5个页面设置:
<%@ ENABLESESSIONSTATE=True %>
而其他页面设置为:
<%@ ENABLESESSIONSTATE=False %>
<SCRIPT type=text/javascript><!--google_ad_client = "pub-1634561494151585";/* 468x60, articlebottom */google_ad_slot = "7716109916";google_ad_width = 468;google_ad_height = 60;//--></SCRIPT><SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript></SCRIPT><SCRIPT> window.google_render_ad(); </SCRIPT>
- 取得所有的Session变量
- 如何取得所有的Session变量
- 如何取得所有的Session变量
- remove所有session中的变量
- 在.net中获取所有session变量的值
- Silverlight中如何与Asp.Net交换变量,取得Session的值问题?
- service--取得所有的service
- spring AOP 取得web的session
- struts2取得request,session,appilcation的方法
- [Java][Spring]随时随地取得Session的方法
- ognl 取得request、session 的值
- struts2取得request,session,appilcation的方法
- struts2取得request,session,appilcation的方法
- ognl 取得request、session 的值
- session变量的操作
- session变量的操作
- 《太阁立志传4》 所有武将卡的取得
- 取得單個資料庫下所有表的信息
- 了解“云计算”概念
- Linux系统中的Shell脚本调试技术
- 为什么总在辩解?
- "衷心感谢您愿意从我们的网站获取更新程序"的解決
- 备份勿忘
- 取得所有的Session变量
- 译文:如何使用SocketAsyncEventArgs类(How to use the SocketAsyncEventArgs class)
- 使用 Bash shell脚本进行功能测试
- 5分钟让你整明白美国金融危机爆发的原因
- 从windows到ubuntu---虚拟光驱的使用
- .net中的常用正则表达式总结
- Head First C# 中文版 图文皆译 第十一章 事件和代理 page500
- 通过帮助查找函数
- 请教一C++for语句段的一个清晰写法?