Asp.net 身份注销其他用户
Asp.net Identity logout other user
我正在使用 Asp.net 身份验证用户身份,我正试图从管理员端锁定任何用户。但是当我锁定任何在线用户时,它并没有注销。我已经阅读了很多关于我的问题的评论,但所有评论都没有用。我尝试 UserManager.UpdateSecurityStamp 注销用户,但效果不佳。
如何在锁定时立即注销用户?
public ActionResult LockUser(string userId)
{
_userManager.SetLockoutEnabled(userId, true);
_userManager.SetLockoutEndDate(userId,DateTime.Today.AddYears(999));
var user = _userManager.FindById(userId);
_userManager.UpdateSecurityStamp(userId);
return RedirectToAction("UserDetail",new { userId });
}
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/UnAuthorize/Index"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, User>(
validateInterval: TimeSpan.FromMinutes(1),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
很可能您缺少 ApplicationUserManager
的 OWIN 注册。您仍然需要让 OWIN 知道如何获取用户管理器,因为它使用它来为用户获取新的安全标记。
在你 Startup.Auth.cs
确保你有这个注册:
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());
我正在使用 Asp.net 身份验证用户身份,我正试图从管理员端锁定任何用户。但是当我锁定任何在线用户时,它并没有注销。我已经阅读了很多关于我的问题的评论,但所有评论都没有用。我尝试 UserManager.UpdateSecurityStamp 注销用户,但效果不佳。 如何在锁定时立即注销用户?
public ActionResult LockUser(string userId)
{
_userManager.SetLockoutEnabled(userId, true);
_userManager.SetLockoutEndDate(userId,DateTime.Today.AddYears(999));
var user = _userManager.FindById(userId);
_userManager.UpdateSecurityStamp(userId);
return RedirectToAction("UserDetail",new { userId });
}
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/UnAuthorize/Index"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, User>(
validateInterval: TimeSpan.FromMinutes(1),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
很可能您缺少 ApplicationUserManager
的 OWIN 注册。您仍然需要让 OWIN 知道如何获取用户管理器,因为它使用它来为用户获取新的安全标记。
在你 Startup.Auth.cs
确保你有这个注册:
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());