Skip to main content
All docs
V25.2
  • UserManager.FindUserByName<TUser>(IObjectSpace, String) Method

    Finds an application user based on the specified user name.

    Namespace: DevExpress.ExpressApp.Security

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

    NuGet Package: DevExpress.ExpressApp.Security

    Declaration

    public TUser FindUserByName<TUser>(
        IObjectSpace objectSpace,
        string name
    )
        where TUser : class, ISecurityUser

    Parameters

    Name Type Description
    objectSpace IObjectSpace

    An Object Space used to search for a user.

    name String

    A System.String value that contains the user name.

    Type Parameters

    Name Description
    TUser

    The user object type.

    Returns

    Type Description
    TUser

    The resulting user object.

    Remarks

    Use this method to search for a user object based on a user name 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 following code snippets (auto-collected from DevExpress Examples) contain references to the FindUserByName<TUser>(IObjectSpace, String) method.

    Note

    The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

    See Also