=波波日志 > Asp.Net/C#/WCF > Session.Abandon的使用注意事项=
[转]Session.Abandon的使用注意事项
关于session对象方法Abandon,使用该方法可以清空session中的值。
首先阅读一下微软的文档:
Remarks
When the Abandon method is called, the current Session object is queued for deletion, but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to Abandon, but not in any subsequent Web pages.
如果调用Abandon 方法的话,在当前页面的脚本执行完之后,当前的session对象将会被删除;在本页中仍然可以调用session对象中存储的值,by www.aspxuexi.com。
For example, in the following script, the third line prints the value Mary. This is because the Session object is not destroyed until the server has finished processing the script.
If you access the variable MyName on a subsequent Web page, it is empty. This is because MyName was destroyed with previous Session object when the page containing the above example finished processing.
The server creates a new Session object when you open a subsequent Web page after abandoning a session. You can store variables and objects in this new Session object.
被删除的session在后面的页面中取值的话,将得到一个空的结果;使用abandon方法后,你可以创建新的session变量Session.Abandon是将服务器上该网站(例如www.aspxuexi.com的所有在线访问者)的所有session都删除.
session是会话级别的变量,即使不调用Abandon方法,在会话超时后,服务器上保留的值仍然会被清空,所有web编程脚本都会有这个问题;建议使用cookies保留长期的会话数据。会话超时后(例如长时间未刷新),标记访问的session SessionID将重新产生,服务器会认为这是一次全新的访问。Sessionid是完全随机的,一个session变量大约会占用10k的内存。(另外一个说法是4k)。需要了解的是,不管程序是否使用session,SessionID总是存在的,而且会以cookie的方式发送到浏览器。
如果网站配备Global.asa(从来没见过现在2007年还有人使用这个东西),Session.Abandon将激活session_onend事件 。
单一用户退出登陆时尽量用清空的方法,而不要用Session.Abandon这删除的方法.
如:
直接将session("userid")变量置空即可`~`
或者使用
来删除session("UserName")的变量引用。
也可用Session.Contents.RemoveAll来删除所有的Session的变量引用。
首先阅读一下微软的文档:
Remarks
When the Abandon method is called, the current Session object is queued for deletion, but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to Abandon, but not in any subsequent Web pages.
如果调用Abandon 方法的话,在当前页面的脚本执行完之后,当前的session对象将会被删除;在本页中仍然可以调用session对象中存储的值,by www.aspxuexi.com。
For example, in the following script, the third line prints the value Mary. This is because the Session object is not destroyed until the server has finished processing the script.
+展开
-VBScript
Session.Abandon
Session("MyName") = "Mary"
Reponse.Write(Session("MyName"))
Session("MyName") = "Mary"
Reponse.Write(Session("MyName"))
If you access the variable MyName on a subsequent Web page, it is empty. This is because MyName was destroyed with previous Session object when the page containing the above example finished processing.
The server creates a new Session object when you open a subsequent Web page after abandoning a session. You can store variables and objects in this new Session object.
被删除的session在后面的页面中取值的话,将得到一个空的结果;使用abandon方法后,你可以创建新的session变量Session.Abandon是将服务器上该网站(例如www.aspxuexi.com的所有在线访问者)的所有session都删除.
session是会话级别的变量,即使不调用Abandon方法,在会话超时后,服务器上保留的值仍然会被清空,所有web编程脚本都会有这个问题;建议使用cookies保留长期的会话数据。会话超时后(例如长时间未刷新),标记访问的session SessionID将重新产生,服务器会认为这是一次全新的访问。Sessionid是完全随机的,一个session变量大约会占用10k的内存。(另外一个说法是4k)。需要了解的是,不管程序是否使用session,SessionID总是存在的,而且会以cookie的方式发送到浏览器。
如果网站配备Global.asa(从来没见过现在2007年还有人使用这个东西),Session.Abandon将激活session_onend事件 。
单一用户退出登陆时尽量用清空的方法,而不要用Session.Abandon这删除的方法.
如:
+展开
-VBScript
session("userid") = ""
直接将session("userid")变量置空即可`~`
或者使用
+展开
-VBScript
Session.Contents.Remove("UserName")
来删除session("UserName")的变量引用。
也可用Session.Contents.RemoveAll来删除所有的Session的变量引用。
类别:Asp.Net/C#/WCF 作者:转载 日期:2011-12-29 【评论:0】
相关文章
暂时没有评论!
发表留言
热门博文
- IE里Cookie跨域不能读取
- web服务因URL意外地以/**结束,请求格式无法识别
- 去掉隐藏asp.net编译出错aspxerrorpath错误参数
- 解决asp.net验证视图状态 MAC 失败
- 找不到System.Web.Script.Services.ScriptService
- 在aspx,ashx页面挂起线程执行
最新博文
- WCF授权-通过扩展自行实现服务授权
- WCF授权-ASP.NET Roles授权[下篇]
- WCF授权-ASP.NET Roles授权[上篇]
- WCF授权-模拟在WCF中的应用
- WCF授权-模拟(Impersonation)与委托(Delegation)
- WCF授权-基于Windows用户组授权[下篇]
随机博文
- 通过自定义ServiceHost实现对WCF的扩展[原理篇]
- Asp.net中 UTF-8编码转换GB2312编码
- C#字符串的驻留(String Interning)
- WCF实现Service Contract的重载(Overloading)
- 在.ashx引用Session失败
- 用.NET动态创建类的实例讲解
广告商赞助

