Skip to content

Instantly share code, notes, and snippets.

@kdarty
Created December 23, 2016 15:32
Show Gist options
  • Save kdarty/85f5760dcd897c7645e805cfb82cb8b6 to your computer and use it in GitHub Desktop.
Save kdarty/85f5760dcd897c7645e805cfb82cb8b6 to your computer and use it in GitHub Desktop.
Here's a tip for Disabling Users with Simple Membership (Microsoft ASP.NET). The Database for Simple Membership includes an "IsConfirmed". This wasn't really intended for use with disabling/locking a User but can sort of work. A better idea would be to have a Role for "Active" Users.

How to lock/unlock a user in MVC SimpleMembership

Stack Overflow Discussion

I find it easiest to use Roles to do this. Have a ActiveUser role and tag your controllers or actions with a Authorize attribute.

[Authorize(Roles = "ActiveUser")]

Then some simple admin to add or remove users from the role to unlock and lock their access to everything protected with that roles attribute.

Roles.AddUserToRole(user.Username, "ActiveUser");

Roles.RemoveUserFromRole(user.Username, "ActiveUser");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment