会话超时在asp.net mvc 4 C#中不起作用.为什么?

Vit*_*lii 12 c# authentication session asp.net-mvc-4

对于我的网站,我在web.config文件中配置了1周的登录会话超时

<system.web>
  <httpRuntime />

  <!-- Session keeps for 7 days -->
    <sessionState timeout="10080"></sessionState>
    <authentication mode="Forms">
      <forms loginUrl="~/" timeout="10080" slidingExpiration="true"/>
    </authentication>
  <!-- Configuration end  -->
</system.web>
Run Code Online (Sandbox Code Playgroud)

这是登录的代码

    [AllowAnonymous]
    [HttpPost]
    public ActionResult Login(string Login, string Password)
    {
        // empty passwords are not allowed
        if (Password == "")
            return Redirect(Request.UrlReferrer.ToString());

        bool LoginResult = WebSecurity.Login(Login, Password, true);
        return Redirect(Request.UrlReferrer.ToString());
    }
Run Code Online (Sandbox Code Playgroud)

我登录,关闭浏览器并再次打开它进入我的网站 - >用户已登录.我关闭浏览器,等待一段时间(约30分钟)转到我的网站 - >用户已注销.为什么?会话应存储7天,但我们甚至没有30分钟.Whan可能是问题的根源?

编辑1 主要想法是我想在几天内回到网站,并仍然使用登录用户打开它

小智 12

可能,您的IIS配置为20分钟TimeOut.

将会话IIS超时更改为1周 24小时,我希望这将解决您的问题.

请参阅

根据设计,超时的最大值设置为24小时.查看Microsoft支持论坛

要实现更大的超时窗口,您可以考虑维护会话状态SQL,如@Marc所示.