使用MVC5进行身份验证超时

问题描述 投票:0回答:1

我正在使用ASP.NET身份与MVC5,并希望在一段时间后过期登录用户。我在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);

但是用户永远不会退出,他们只会永远登录。

asp.net session cookies asp.net-mvc-5
1个回答
0
投票

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

Identity的设置位于App_Start \ Startup.Auth.cs中:

app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/"),
        ExpireTimeSpan = TimeSpan.FromMinutes(24),
        SlidingExpiration =false
    });
© www.soinside.com 2019 - 2024. All rights reserved.