我在web.config里设置了timeout=2 但是2分钟后我的session依然存在没有注销,Session_End方法没有运行
  用的IIS7 win2008系统   请教高手这是为何?

解决方案 »

  1.   

    只有另外一个请求、另外一个Session访问服务器,前面的Session才会过期。
      

  2.   


    那个 session 的 timeout 是干吗用的? 时间到了还需要另外一个请求、另外一个Session访问服务器才注销吗?  那我如何实现自动注销?
      

  3.   

    Session_End只有SessionMode为Inproc的情况下才触发
    另外。你的iis要配置成经典模式
      

  4.   


    我不记得那一本入门书、或者msdn上明确讲解这个机制。但是我一旦跟别人讨论这个Session过期,都是基于asp.net的框架源代码的,上面的代码非常清晰易懂,每当当一个请求到达服务器的时候,服务器都会去检查有没有以前的Session需要做过期处理。因此,就算你设置为10分钟,也不是10分钟到点就过期,而是10分钟之后的第一次其它请求(包括本session的请求)到达服务器时,所有本来应该过期的session们才过期。
      

  5.   

    SessionMode设置为Inproc或者手动
      

  6.   

    Session_End只有SessionMode为Inproc的情况下才触发
      

  7.   

    session过起原理。是
    例如默认20分钟 你没有做任何动作。在刷新页面就会过期但是一旦在20分钟内做任何一个操作就会还有持续有效时间。
    例如QQ的自动离开状态
    你不操作电脑他就自动离开 而你一直在做任何操作QQ他就不会离开
      

  8.   


     我的是 Inproc模式 我的IIS也配置了经典模式 但是时间到了没有效果
      

  9.   


    我设置了 Inproc  但是没有效果
      手动是什么意思?  手动清空cookie 那些的吗?
      

  10.   

    InProc模式应该是可以的,还与你的iis里面的应用程序池 模式有关系
    另外,你测试是否过期的方法是什么?
    在过期之前,你是不能再访问这个站点的,否则,过期时间会往后推迟一个过期时间
      

  11.   

     我在Session_End里写了一条数据库更新语句 但是一直没有更新我没有访问这个站点 我最小化浏览器后就在没管过 但是在新开的浏览器里有进行其他网站的操作 
      

  12.   

    我在Session_End里写了一条数据库更新语句 但是一直没有更新?
    我猜想是你更新数据库的错误导致的。Session_End事件里面只有Session.SessionID可用。其他的如Session["xxx"]是得不到的。你可以写成文件测试
      

  13.   

    你可以
    void Session_End(object sender, EventArgs e)
    {
        System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "log.txt");
        s.WriteLine("过期了 ");
        s.Close();
    }测试
      

  14.   

    这个我测试了 有运行 但是为什么我刷新我的网站后 session值还在? 不能注销然后跳到登录页面啊?
      

  15.   


    如果Session["xxx"]得不到的话  我写了
                         Session.Clear();Session.RemoveAll();Session.Abandon();
    然后在页面的Page_Load里写了Session["xxx"]判断 为空跳转页面 这个为什么没有作用?
                
                
      

  16.   

     protected void Session_End(object sender, EventArgs e)
            {
                Session["Lg_User"] = "";
                Session.SessionID.ToString();
                Session.Clear();
                Session.RemoveAll();
                Session.Abandon();
                //}
                System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "Sessionlog.txt");
                s.WriteLine("过期了"+ Session.SessionID.ToString()+"----"+Session["Lg_User"]+" ");
                s.Close();
              
            }
      

  17.   

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                Unit unit = new Unit();
                this.Label1.Text = "当前用户:" + MapgisEGov.User.User.GetUserName(this.Context);
                this.Label2.Text = "所属部门:" + MapgisEGov.User.User.GetUserDeptName(this.Context);
                this.Label3.Text = "上次登陆时间:";
                this.Label4.Text = "累计登陆次数:";
                DBAccess access = new DBAccess();
                string strSql = "select LSLOADTIME , LOADCOUNT from USERLOGINFO where USERID ='" + MapgisEGov.User.User.GetUserCode(this.Context) + "'";
                DataSet dataSet = access.GetDataSet(strSql);
                if ((dataSet.Tables.Count > 0) && (dataSet.Tables[0].Rows.Count > 0))
                {
                    this.Label3.Text = this.Label3.Text + dataSet.Tables[0].Rows[0]["LSLOADTIME"].ToString();
                    this.Label4.Text = this.Label4.Text + dataSet.Tables[0].Rows[0]["LOADCOUNT"].ToString();
                }
            }
            if (base.Session["Lg_User"] == null || base.Session["Lg_User"].ToString().Equals(""))
            {
                
                
                Response.Write("<script>top.location.href='about:blank';</script>");
               
            }        else 
            {
                Response.Write("<script>alert('"+Session["Lg_User"]+"');</script>");
            }
      

  18.   

    我所学的知识告诉我:Session是客户端窗体会话,客户端窗体关闭Session就会失效,也许您这点是更高的看法,我无法理解
      

  19.   

    测试过程
    Global.asax
    <%@ Application Language="C#" %><script runat="server">
        void Session_Start(object sender, EventArgs e) 
        {
        }    void Session_End(object sender, EventArgs e) 
        {
          System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "Sessionlog.txt",true);
          s.WriteLine( DateTime.Now.ToString() + " 过期了 " + Session.SessionID.ToString());
          s.Close();
        }
           
    </script>
    web,config
    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <pages enableSessionState="true"/>
        <sessionState mode="InProc" timeout="2"/>
        <compilation debug="true" defaultLanguage="C#">
        </compilation>
        <globalization responseEncoding="utf-8"/>
      </system.web>
    </configuration>default.aspx
    <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
      protected void Page_Load(object sender, EventArgs e)
      {
        Response.Write(Session.Timeout);
        if (!Page.IsPostBack)
        {
          Session["x"] = DateTime.Now.ToString();
        }
      }  protected void Button1_Click(object sender, EventArgs e)
      {
        if (Session["x"] != null)
        {
          Response.Write(Session["x"].ToString());
        }
      }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title></title>
    </head>
    <body>
      <form id="form1" runat="server">
      <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
      </form>
    </body>
    </html>
      

  20.   


    对于asp.net开发人员,口里所说的Session是指他在代码中使用到的那个Session集合,是具体的代码,而不是一些其它文章中的概念。对于这个Session集合代码而言,他有源代码,源代码比一些介绍文章岂不是更准确。
      

  21.   

    如果你认为客户端窗体关闭,那么asp.net就去执行删除Session集合中的数据动作,那么我只能说你有些死抠书本了。你所学的知识,并没有说“就会失效”的具体测试标准是什么,你可能都没有想到lz遇到的“Session_End并不立即执行”这个事情吧。那么现在你遇到了!
      

  22.   

    唉,其实读书时可以多想想,当客户端窗体关闭的时候,asp.net应用程序怎么知道客户端窗体关闭了呢?
      

  23.   


    大侠,我读书时没好好读落得现在这下场,影响Session的可能性还有哪些啊? 请指点下吧
      

  24.   

    这些
    Session["Lg_User"] = "";
      Session.SessionID.ToString();
      Session.Clear();
      Session.RemoveAll();
      Session.Abandon();
    都没有用
    Session["Lg_User"]已经为null。你还s.WriteLine("过期了"+ Session.SessionID.ToString()+"----"+Session["Lg_User"]+" ");什么啊