c# - session 超时在 asp.net mvc 4 C# 中不起作用。为什么?

标签 c# asp.net-mvc-4 session authentication

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

<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>

这是登录代码

    [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());
    }

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

编辑 1 主要想法是我想在几天后返回该站点并仍然以登录用户打开它

最佳答案

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

IIS session 超时更改为 1 周 24 小时,希望这能解决您的问题。

引用this

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

要获得更大的超时窗口,您可以考虑在 SQL 中维护 session 状态,正如@Marc 所建议的。

关于c# - session 超时在 asp.net mvc 4 C# 中不起作用。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22809817/

相关文章:

c# - 如何编写在 foreach 循环中设置属性值的方法(Silverlight 和 MVVM 相关)

asp.net-mvc - AngularJS 和 ASP.NET MVC 集成和引导

asp.net-mvc-4 - 使用 Bootstrap 日期时间选择器、Asp.Net MVC4 应用程序中的 Jquery 验证插件验证日期和日期时间

php session 在本地主机上工作,但在 vps 网络服务器上不工作

php - 拉拉维尔 : Check if session exists necessary?

c# - c#中保留字符的正则表达式问题

c# - XmlReader.GetAttribute() 不会抛出异常

php - 如何在 mysql 中联合随机选择的行?

c# - 性能计数器 NextValue 返回相同的先前值

asp.net-mvc-4 - 如何使用SimpleMembership管理个人资料?