2017-12-28 59 views
0

私はMVC5でASP.NET IDを使用しており、設定された期間を過ぎるとログインしたユーザーの有効期限を切ることを望みます。私は、web.configファイルでのsystem.webするセクションを追加しました:MVC5での認証タイムアウト

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

しかし、ユーザーがログオンされることはありません。私も永続的なCookieを使用しないようにログインコードを変更した

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

彼らは永遠にログインしたままです。

答えて

0

フォーム認証とASP.NET IDの間に違いがあるようです。 Identityを使用している場合、web.configの設定は効果がありません。

アイデンティティの設定がApp_Start \ Startup.Auth.csにあります

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