Base solution for your next web application
Open Closed

Can't create a new user with no Tenant system. #561

mrvithan created

I try to create a new user with no Tenant in an AppService using this code :

//Create user
        var user = new User
            Name            = input.Name.Trim(),
            Surname         = input.Name.Trim(),
            EmailAddress    = input.Email.Trim(),
            IsActive        = true,
            TenantId        = 1

        user.UserName   = input.Code;
        user.Password   = new PasswordHasher().HashPassword(input.Password);
        user.Roles      = new List<UserRole>();
        foreach (var agentRole in _roleManager.Roles.Where(r => r.Name == StaticRoleNames.Host.Agent).ToList())
            user.Roles.Add(new UserRole { RoleId = agentRole.Id });


I also setup a new role called 'Agent' with Tenant = 1. There is no error but the user has not been created.

Any suggestion ?

2 Answer(s)
  • 0
    mrvithan created

    Ok i found the error. The email is duplicated...!!! But it should throw an exception..

  • 0
    hikalkan created
    Support Team

    UserManager.Create returns an IdentityResult. Have you checked it?