首页 文章

使用SqlServer模式时,会话超时不起作用

提问于
浏览
0

我正在开发ASP.Net MVC应用程序 .

我们使用了sessionState模式SQLServer,我将超时设置为20分钟 .

<sessionState mode="SQLServer" 
              sqlConnectionString="data source=127.0.0.1;user id=sa;password=sa" 
              cookieless="false" 
              timeout="2" />

代码在Web配置中是这样的 .

我也设置了登录页面 .

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

现在,当会话到期时,我想要将用户导航到登录页面 .

I checked many things but i was unable to understand how it exactly works? and how can i navigate user login page on session expire?

它正在InProc模式下工作 . 我以相同的方式使用它,并且用户被重定向到会话到期时登录 .

但我无法在SQLServer模式下完成同样的事情 .

我无法理解我错过了什么?

我查了Session State也发现Session timeout handled in SQLServer Mode

编辑: - 每当为该会话执行另一个http请求时,我想将用户重定向到登录页面 .

1 回答

  • 1

    通常浏览器不知道服务器上发生了什么 . 除非发生HTTP往返,否则它将记住从呈现页面开始的会话状态 .

    此外,您的会话cookie可能是HttpOnly,因此页面无法检查是否存在会话cookie .

    实现目标的一种方法是:

    • 在页面中添加隐藏的iFrame . 将iFrame的SRC设置为网站中的处理程序

    • 除了返回200 OK,加上刷新标头设置为几秒之外,处理程序不必做太多操作,以便处理程序不断轮询 .

    context.Response.AddHeader("REFRESH", "2");
    
    • 将帧破解程序代码添加到登录页面
    if (top.location != location) {
        top.location.href = document.location.href ;
     }
    
    • 当对过期会话发出处理程序请求时,它将通过表单身份验证重定向到登录页面;当返回登录页面时,它将破坏您的iFrame并将整个窗口重定向到登录页面 .

    或者,您可以执行其他人所做的事情,即等待用户请求其他页面 .

相关问题