Base solution for your next web application
Open Closed

How to create user from code #3314


User avatar
0
malomatia created

Dears, How to create a user from the .net code and assign him specific roles ?

Thank you !


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use UserManager for that.

    await UserManager.CreateAsync(user)
    

    You can also add any role to user's Roles list before creating it.

    user.Roles.Add(new UserRole(TenantId, user.Id, role.Id));
    

    Thanks.