Skip to main content
All docs
V24.1
.NET 6.0+
  • The page you are viewing does not exist in the .NET Framework 4.5.2+ platform documentation. This link will take you to the parent topic of the current section.

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

UserManager Class

Exposes API required to manage user objects in the database. Use Dependency Injection to access this class’s instance in a .NET 6+ application.

Namespace: DevExpress.ExpressApp.Security

Assembly: DevExpress.ExpressApp.Security.v24.1.dll

NuGet Package: DevExpress.ExpressApp.Security

#Declaration

public sealed class UserManager

#Remarks

The UserManager service exposes methods that you can use to create and access application users and their login information. You can also use UserManager to interact with the user lockout mechanism.

The following code snippet demonstrates how to use the UserManager service to create a new application user. The XAF Solution Wizard generates equivalent logic in the application’s Module Updater code.

File: MySolution.Module/DatabaseUpdate/Updater.cs

using DevExpress.ExpressApp.Security;
// ...
public class Updater : ModuleUpdater {
    // ...
    public override void UpdateDatabaseAfterUpdateSchema() {
        base.UpdateDatabaseAfterUpdateSchema();
        UserManager userManager = ObjectSpace.ServiceProvider.GetRequiredService<UserManager>();
        // If a user named 'User' doesn't exist in the database, create this user.
        if(userManager.FindUserByName<ApplicationUser>(ObjectSpace, "User") == null) {
            // Set a password if the standard authentication type is used.
            string EmptyPassword = "";
            var userCreationResult = userManager.CreateUser<ApplicationUser>(ObjectSpace, "User", EmptyPassword, (user) => {
                // Add the Users role to the user
                user.Roles.Add(defaultRole);
            });
            // ...
        }
        // ...
        ObjectSpace.CommitChanges(); // This line persists created object(s).
    }
}

For more use case scenarios, refer to the descriptions of the UserManager class members. For example:

  • AddLogin - Adds login method information to a user record.
  • FindUserByName - Finds an application user object based on a user name.
  • GetAuthenticationToken - Generates an authentication token for a user with the capability to add additional claims to the token.
  • GetCurrentPrincipal - Gets the current user’s ClaimsPrincipal object.
  • IsLockedOut - Demonstrates how to interact with the user lockout mechanism.

#Inheritance

Object
UserManager
See Also