Asp.net Identity logout other user

Tolga Kısaoğulları

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))
                }
            });
trailmax

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.

In you Startup.Auth.cs make sure you have this registration:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Asp.Net Identity Renewal messing with Logout

How to sign out other user in ASP.NET Core Identity

Using ASP.net Identity user with other tables

Cookie not deleted after logout with Asp.Net 5 Identity 3.0

ASP.Net Identity Force Logout From SQL

How to get asp.net identity logout to work?

Logout & ReturnUrl | ASP.Net Core Identity MVC | Authentication

ASP.NET Identity and SignalR getting user

ASP.NET Core Identity user groups

How to edit a user in ASP.NET Identity

Updating user data - ASP.NET Identity

Verify user device in asp.net identity

ASP.NET Identity Update User - Nullreference

ASP.NET Identity - Extend available fields of User.Identity

.Net5 Identity Logout

Prevent user to go back after logout in asp.net mvc

How to logout user in OWIN ASP.NET MVC5

ASP.NET Identity 2 - logout not working when sign in on foo.com and logout on username.foo.com

How to Logout user from a particular session Identity Server 4, .Net Core?

How do I persist a ASP.NET Identity Claim on a cookie until logout?

ASP.NET Identity 2 with Google login... Logout doesn't work

Why does Logout in ASP.NET Identity use POST instead of GET?

How to move ASP.net identity to other context

ASP.NET Identity Manager to manage page level user access

Refresh user cookie ticket in ASP.Net Core Identity

ASP.net Identity OWIN cookie when user roles change?

ASP.NET Identity record user registration and last logged on time

Checking if a user is in a role in asp.net mvc Identity

asp.net identity 2.0 unity not resolving default user store