如果我将会话超时设置为少于20分钟,则一切工作正常。
但是,如果> 20分钟,则无法正常工作。在VS 2013和Production IIS中会发生这种情况。
这是我使用的代码。
如何解决该问题?谢谢!
启动授权
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;
}
PS WEB.CONFIG
<sessionState mode="InProc" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" defaultUrl="~/Account/Login" name="MyApp123" />
</authentication>
听起来您的web.config中仍然有FormsAuthentication配置。您正在使用ASP.NET Identity,它与旧的FormsAuthentication冲突。
更改为此:
<authentication mode="None"/>
并确保您有以下内容:
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
您也可以只使用asp.net身份生成一个默认的Web项目,并查看web.config,它将具有相同的条目。请注意,V1身份模板具有一个拼写错误,该拼写错误在remove元素中使用了“ FormsAuthenticationModule”而不是“ FormsAuthentication”。如果您使用的是v2或更高版本,他们会修复该错字。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句