簡體   English   中英

Asp.net Identity注銷其他用戶

[英]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))
                }
            });

很可能您缺少使用OWIN注冊ApplicationUserManager 您仍然需要讓OWIN知道如何獲取用戶管理器,因為它使用它來為用戶獲取新的安全標記。

在你的Startup.Auth.cs確保你有這個注冊:

app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM