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.

UserManager.CreateUser<TUser>(IObjectSpace, String, String, String, Action<TUser>, Boolean) Method

Creates a new user with the specified settings.

Namespace: DevExpress.ExpressApp.Security

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

NuGet Package: DevExpress.ExpressApp.Security

Declaration

public UserResult<TUser> CreateUser<TUser>(
    IObjectSpace objectSpace,
    string userName,
    string loginProviderName,
    string providerUserKey,
    Action<TUser> customizeUser = null,
    bool autoCommit = true
)
    where TUser : class, ISecurityUserWithLoginInfo

Parameters

Name Type Description
objectSpace IObjectSpace

An Object Space used to create the user.

userName String

A user name for the new user.

loginProviderName String

The name of the login provider for which to create a user.

providerUserKey String

The user login for the specified login provider.

Optional Parameters

Name Type Default Description
customizeUser Action<TUser> null

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

autoCommit Boolean True

A boolean value that specifies whether or not to automatically commit the changes to the Object Space.

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 overload of the CreateUser method to create a user for a specific authentication provider.

using DevExpress.ExpressApp.Security;
using Microsoft.Extensions.DependencyInjection;
// ...
// Use Dependency Injection to access the IServiceProvider.
var userManager = serviceProvider.GetRequiredService<UserManager>();
string providerUserKey = Guid.NewGuid().ToString();
var userResult = userManager.CreateUser<ApplicationUser>(os, "User", "ProviderName", providerUserKey);

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