zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Oracle基础(五) 权限管理
    Oracle基础(四) 用户管理
    Oracle基础 PL-SQL编程基础(4) 异常处理
    Oracle基础 PL-SQL编程基础(1) 变量和常量
    bash: ifconfig: command not found 问题解决
    chrome innerHTML赋值
    IE下设置body{overflow:hidden;}失效Bug
    EXCEL保存提示“隐私问题警告:此文档中包含宏……”解决办法
    启用SQL Server 2008的专用管理员连接(DAC)
    CSS3 弹性盒模型 box-flex
  • 原文地址:https://www.cnblogs.com/imust2008/p/5509896.html
Copyright © 2011-2022 走看看