사용자를 잠그는 동안 인증 쿠키가 무효화되는 SecurityStamp도 변경되었습니다. Startup.Auth에서 찾을 수있는 통합 아이덴티티 2.0 메커니즘은 쿠키 무결성을 매회 확인 (기본값 : 30 분)하고 유효하지 않은 경우 사용자를 로그 아웃합니다 (예 : 다른 SecurityStamp로 쿠키가 있음). 수표에 대한 시간 지연은 변경 될 수 있지만 제 프로젝트에 대한 권리가 있다고 생각합니다.
이 코드 부분은 일부 사용자 쿠키를 무효화하고 매일 검사를 예약하여 실제로 실행하면됩니다.
var userManager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = userManager.FindByName(username);
userManager.SetLockoutEnabled(user.Id, true);
userManager.SetLockoutEndDate(user.Id, DateTime.MaxValue);
user.SecurityStamp = Guid.NewGuid().ToString("D");
userManager.UpdateSecurityStamp(user.Id);
쿠키 유효성 확인 및/또는 재생성을 담당하는 부분은 이미 있지만 실수가없는 경우 Identity 2.0에서만 제공됩니다. 신용이 그 사람에게 간다, 그래서 내가 다른 글에서 유래 여기에 모든이를 발견
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
:이 구성이 Startup.Auth.cs 파일에이 같이 보입니다입니다.
케빈 라파이 (Kevin Raffay)의 답변이 확실하게 작동하기 때문에 나는이 문제에 익숙하지 않아 답변으로 표시 할 것이므로 어떤 접근 방식이 더 좋을지 잘 모르겠습니다.
흠 ....이 방법은 틀림 없지만 데이터베이스를 계속 확인하고 싶지 않았기 때문에 다른 솔루션을 사용했습니다. – Dino