Enable/disable user
Hi
What programmatic feature can I use in SF to enable/disable a user from logging in? A code example would be helpful.
Thanks
Regards
Hi John,
The code below works for me fine:
UserManager manager = UserManager.GetManager();User user = manager.GetUser("testuser");user.SetIsLockedOut(true);user.SetLastLockoutDate(DateTime.UtcNow);//uncomment to unlock a user//user.UnlockUser();manager.SaveChanges();Hello ,
The easiest way would be to set the IsApproved property of the user - it gets or sets whether the membership user can be authenticated. For example:
public virtual void ChangeStatus(User user, string command) var manager = UserManager.GetManager(); var currentUser = manager.GetUser(user.Id); if (currentUser != null) if (command == "Disable") currentUser.IsApproved = false; else // we assume it is allow currentUser.IsApproved = true; manager.SaveChanges();