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:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?