Search code examples
sql-serverasp.net-mvcasp.net-identity

ASP.Net Identity Force Logout From SQL


I'm using the ASPNET Identity tables for my MVC 5 application. Each night we perform "maintenance" on our database. If we modify something under that user, I want to inactivate their current session so that the next action they perform in the web application will kick them back to the login screen. The authentication/authorization already is built into my application using AspNet.Identity. I just need a way to wake it up by setting a flag if it exists.

For example the ASPNETUsers table has an "Inactive" column, but that's too permanent. I'm looking for the "ThisGuyIsLoggedIn" column.

This was close to the same problem, but the answer was to manage it from within MVC, which is not an option.

forcefully log out a specific user among all online users


Solution

  • After playing with some of the columns I realized, you can change the SecurityStamp column which will invalidate the user and cause any authentication to fail. Just don't change it to NULL.

     UPDATE AspNetUsers
     SET SecurityStamp = NEWID()
     WHERE Id = @USER_ID