gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 08:20:54 24 4
gpt4 key购买 nike

对于我的网站,我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com