【发布时间】:2014-12-13 03:02:37
【问题描述】:
如果我将会话超时设置为少于 20 分钟,一切正常。
但如果超过 20 分钟,它就不起作用。它发生在 VS 2013 和生产 IIS 上。
这是我用过的代码。
如何解决这个问题?谢谢!
STARTUP.AUTH
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
var sessionTimeout = 5;
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeout),
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
}
GLOBAL.ASAX
protected void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 5;
}
附注WEB.CONFIG
<sessionState mode="InProc" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" defaultUrl="~/Account/Login" name="MyApp123" />
</authentication>
【问题讨论】:
-
你试过用 ExpireTimeSpan = new TimeSpan(0, 0, 5, 0)
-
解释什么是“不起作用”。有没有超时?它仍然在 20 分钟超时?根本没有会话?你如何衡量它的超时?仅供参考,身份验证超时不是会话超时,它们是两个不同的东西。
-
@ErikFunkenbusch 看,我通过我的代码设置了 10 小时的超时时间。但它会在 20 分钟后过期。这就是问题所在。
-
您可以将会话存储在 SQL 数据库中或增加 IIS 的空闲超时。我建议会话数据库是一种更好的方法,因为您不应该真正依赖 InProc,尤其是如果您希望会话持续 10 小时。
-
@ClarkKent - 如果您使用的是 ASP.NET Identity,您应该有 Authentication mode="None",并且您应该在模块中有一个 remove 语句来删除 FormsAuthentication。
标签: asp.net-mvc iis session-timeout