MVC5的身份验证超时



我正在使用ASP。NET标识,并且希望在设置的期限后使已登录用户过期。我在web.config中为system.web添加了一个部分:

<authentication mode="Forms">
<forms timeout="1" slidingExpiration="false"/>
</authentication>

我还更改了登录代码,使其不使用持久cookie:

var authenticationManager = HttpContext.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);

但用户永远不会注销,他们只是永远保持登录状态。

表单auth和ASP之间似乎有区别。NET标识。如果您使用的是Identity,则web.config设置没有任何效果。

"标识"的设置位于"应用程序启动\启动"中。Auth.cs:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/"),
ExpireTimeSpan = TimeSpan.FromMinutes(24),
SlidingExpiration =false
});

最新更新