Session.Abandon-Session.Clear-Session.RemoveAll
System.Web.UI.Page.Session属性和System.Web.HttpContext.Session属性 都是System.Web.SessionState.HttpSessionState类
这三种方法都可以清除session.
Session.Clear()和Session.RemoveAll()是完全一样的,即Clears all values from the session-state item collection.
Session.RemoveAll()内部就是调用了Session.Clear()
源码
// System.Web.SessionState.HttpSessionState
/// <summary>Removes all keys and values from the session-state collection.</summary>
public void RemoveAll()
{
this.Clear();
}
以上两种方法和Session.Abandon()是有区别的。
以上两种方法,只是清空了键值集合,而Abandon是Ends the current session.意味着Session对象被销毁destroyed,当然其保存的键值集合也会同样消失...
InProc模式下abandon方法会引发Session_End事件
Once the Abandon method is called, the current session is no longer valid and a new session can be started. Abandon causes the End event to be raised. A new Start event will be raised on the next request.
Abandon方法调用后,不是马上销毁,而是等待剩下的脚本执行完毕,因此仍在在随后的代码中被访问,但是本次请求完毕,随后的请求就无法继续访问到了
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 theAbandon method but not in any subsequent Web pages.
<%
Session.Abandon
Session("MyName") = "Mary"
Reponse.Write(Session("MyName")) //本次请求仍然有值
%>
新的请求将会创建新的Session对象,虽然仍然存储相同的键值,例如
Session("MyName") = "Mary" ;
,但是这个Session已经是新对象了
另外,如果inproc模式下,设置的时间超时,会自动调用Abandon方法
The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandonmethod explicitly, the server destroys these objects when the session times out.
https://msdn.microsoft.com/en-us/library/ms524310(v=vs.90).aspx
Session.Abandon-Session.Clear-Session.RemoveAll的更多相关文章
- Session.Abandon, Session.Clear和Session.Remove的区别
Session.Clear()就是把Session对象中的所有项目都删除了, Session对象里面啥都没有.但是Session对象还保留. Session.Abandon()就是把当前Session ...
- Session.Abandon和Session.Clear的实现和区别
我在网上找了一个比较贴切的描述: Session.Clear()就是把Session对象中的所有项目都删除了,Session对象里面啥都没有.但是Session对象还保留.Session.Abando ...
- Session.Abandon和Session.Clear有何不同 (转)
Session.Clear()就是把Session对象中的所有项目都删除了, Session对象里面啥都没有.但是Session对象还保留.Session.Abandon()就是把当前Session对 ...
- Session.Abandon与Session.Clear之间的区别
Session.Clear()就是把Session对象中的所有项目都删除了,Session对象里面什么都没有.但是Session对象还保留. Session.Abandon()就是把当前Session ...
- HttpContext.Current.Session.Abandon() 大坑 要注意
HttpContext.Current.Session.Abandon(); 如果在调用以上代码之后再存储session 在当前上下文之内是可以访问session的.. 但是页面跳转之后..在其他页面 ...
- Hibernate之Session缓存以及操作Session缓存的相关方法
1.Session概述 A.Session 接口是 Hibernate 向应用程序提供的操纵数据库的最主要的接口, 它提供了基本的保存, 更新, 删除和加载 Java 对象的方法. B. Sessio ...
- 六十一:Flask.Session之flask操作session
1.设置session:使用flask.session就可以操作字典,操作方式和操作字典一样:session['key']=value2.获取session,和获取字典的值一样:session['ke ...
- Django(十三)状态保持 —— cookie与session+ajax异步请求+session记住登录状态+cookie记住登录名密码
一.状态保持的概述 http协议是无状态的.下一次去访问一个页面时并不知道上一次对这个页面做了什么.因此引入了cookie.session两种方式来配合解决此问题. Duplicate entry:重 ...
- 懒加载session 无法打开 no session or session was closed 解决办法(完美解决)
首先说明一下,hibernate的延迟加载特性(lazy).所谓的延迟加载就是当真正需要查询数据时才执行数据加载操作.因为hibernate当中支持实体对象,外键会与实体对象关联起来.如 ...
- 【荐】PHP Session和Cookie,Session阻塞,Session垃圾回收,Redis共享Session,不推荐Memcached保存Session
什么是 Session 在 web 应用开发中,Session 被称为会话.主要被用于保存某个访问者的数据. 由于 HTTP 无状态的特点,服务端是不会记住客户端的,对服务端来说,每一个请求都是全新的 ...
随机推荐
- leetcode 21.Merge Two Sorted Lists ,java
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- BMP格式介绍(一)
原理篇: 一.编码的意义. 让我们从一个简单的问题开始,-2&-255(中间的操作符表示and的意思)的结果是多少,这个很简单的问题,但是能够写出解答过程的人并不 多.这个看起来和图片格式没有 ...
- Win10的Hosts文件修改后无法保存的问题解决方法,实测可以
1.hosts文件是什么?有什么作用呢? Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个 ...
- CAN总线扩展数据帧介绍
在扩展CAN 数据帧中,紧随SOF 位的是32 位的仲裁字段.仲裁字段的前11 位为29 位标识符的最高有效位(Most Significant bit,MSb)(基本lD) .紧随这11 位的是替代 ...
- java里监听相关ActionListene的理解。========此代码是错误的,
package com.aa; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event. ...
- openstack及组件简要介绍
为什要用云? 一.简单的说就是对资源更加合理的分配,使用,比如硬件的数量,带宽等等这些,因为你不能机器买来不需要了再卖掉(当然也可以),带宽跟机房签合同得来一年的,中间不够了也不能加,超了也不退钱 二 ...
- java 最差实践
HashMap size 陷阱: 错误写法: Map map = new HashMap(collection.size()); for (Object o : collection) { map.p ...
- Dynamics CRM early binding and late binding
The key advantage of late bound entity classes is that customer entities and attributes not avaliabl ...
- mysql库操作
一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等performance_schema: MyS ...
- 简单 JS 弹出层 背景变暗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...