Asp.net身份注销其他用户 [英] Asp.net Identity logout other user
问题描述
我正在使用Asp.net Identity来验证用户身份,并且正在尝试从管理员端锁定任何用户.但是,当我锁定任何在线用户时,它并没有注销.我已经阅读了许多有关我的问题的评论,但所有评论均无效.我尝试了UserManager.UpdateSecurityStamp来注销用户,但效果不佳. 锁定用户后如何立即注销用户?
I'm usigin Asp.net Identity to authenticate user and I'm trying to lockout any user from admin side. But when I lockout any user who is online, It didn't logout. I have read many comments about my problem but all of them didn't work. I tried UserManager.UpdateSecurityStamp to logout user but it didn't work as well. How can I logout the user instantly when I lockout it ?
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知道如何获取用户管理器,因为它使用它来为用户获取新的安全标记.
Most likely you are missing registration of ApplicationUserManager
with OWIN. You still need to let OWIN know how to get user manager because it uses it to get a new security stamp for a user.
在您的Startup.Auth.cs
中,请确保您已注册:
In you Startup.Auth.cs
make sure you have this registration:
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());
这篇关于Asp.net身份注销其他用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!