私はASP.NET IDを使用しています。ユーザーアカウントをブロックするとすぐにログアウトする必要があります。 これは私のコードです:セキュリティー・スタンプがユーザーをログアウトしないのはなぜですか?
await UserManager.SetLockoutEnabledAsync(user.Id, true);
await UserManager.SetLockoutEndDateAsync(user.Id,DateTime.Today.AddYears(10));
await UserManager.UpdateSecurityStampAsync(user.Id);
とStartup.Auth.cs
で:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(0),
regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie))
}
});
しかし、それは、ユーザーがサインアウトしません。私は間違って何をしていますか?
私はそのIDに基づいてユーザーをサインアウトしたいです。私には管理者権限があり、ユーザーをブロックできます。ユーザーがブロックされている場合は、ログアウトする必要があります。 –
ユーザが次回訪問時に検証されたときに、明示的に 'UserManager.UpdateSecurityStampAsync(userId);'を呼び出す必要があります。このために、 'ICookieAuthenticationProvider'を実装し、それを' OnValidateIdentity'コールバックで呼び出すことができます。 – Irshu