Delete users

Deleting a single user

To delete a specific user you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get the user.
    Get an instance of the user. For more information, read For developers: Query users.
  3. Get the user profile.
    You must also delete any existing profiles for the specified user. Note that if you have more than one profile type for each user, you must get all the profiles related to the user and delete them. For more information, read For developers: Query user profiles.
  4. Mark the user and the user profile for deletion.
    To mark the user and the user profile to be deleted, you call the Delete method of the respective manager.
  5. Save changes.
    To actually delete  the user and the user profile, you must save the changes to the managers.
Here is a code example:

Deleting all users

To delete all users, you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get all users, excluding the current one.
    For more information, read For developers: Query users.
  3. Iterate through the users collection.
  4. Get the user profile.
    You must also delete any existing profiles for the specified user. Note that if you have more than one profile type for each user, you must get all the profiles related to the user and delete them. For more information, read For developers: Query user profiles.
  5. Mark the user and the user profile for deletion.
    To mark the user and the user profile to be deleted, you call the Delete method of the respective manager.
  6. Save changes.
    To actually delete the user and the user profile, you must save the changes to the managers.
Here is a code example:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?