expressappframework-devexpress-dot-expressapp-dot-security-b7a83e71.md
Exposes API required to manage user objects in the database. Use Dependency Injection to access this class’s instance in an application.
Namespace : DevExpress.ExpressApp.Security
Assembly : DevExpress.ExpressApp.Security.v25.2.dll
NuGet Package : DevExpress.ExpressApp.Security
public sealed class UserManager
Public NotInheritable Class UserManager
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 Template Kit 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:
ClaimsPrincipal object.Object UserManager
See Also