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

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 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.CreateUser<TUser>(IObjectSpace, String, String, Action<TUser>) Method

Creates a new user with the specified settings.

Namespace: DevExpress.ExpressApp.Security

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

NuGet Package: DevExpress.ExpressApp.Security

#Declaration

public UserResult<TUser> CreateUser<TUser>(
    IObjectSpace objectSpace,
    string userName,
    string password,
    Action<TUser> customizeUser = null
)
    where TUser : class, ISecurityUserWithLoginInfo, IAuthenticationStandardUser

#Parameters

Name Type Description
objectSpace IObjectSpace

An Object Space used to create the user.

userName String

A user name for the new user.

password String

A password for the new user.

#Optional Parameters

Name Type Default Description
customizeUser Action<TUser> null

A delegate method used to additionally customize the created user object.

#Type Parameters

Name Description
TUser

A user object type.

#Returns

Type Description
DevExpress.ExpressApp.Security.UserResult<TUser>

An object that contains the result of the user creation operation.

#Remarks

Use this method to create and customize a new application user as the following code snippet demonstrates:

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).
    }
}

The CreateUser method returns a UserResult object. This object exposes the following properties:

Succeeded
A boolean property that indicates whether or not a user was created successfully.
User
The created user object.
Error
If user creation fails, this property contains the resulting Exception.
See Also