I have a backend website (ASP.NET MVC) that has his own tenantId (ASP.NET Identity) and this website can create users for other websites with their own tenantId's (all Tenant's are in the same database).
The problem is that when i use the Create
method from ApplicatoinUserManager
, the ApplicationUser
even if i put the TenantId corresponding to the website that the user belongs, the user is created with the TenantId of my backend website.
Why this is happening?
Here is the register code for the users:
internal IdentityResult Register(string username, string email, string password, out ApplicationUser user, int? tenantId = null) {
user = new ApplicationUser {
UserName = username,
Email = email,
IsAnonymous = false,
Comment = string.Empty,
IsApproved = true,
IsLockedOut = false,
FailedPasswordAnswerAttemptCount = 0,
FailedPasswordAttemptCount = 0,
};
if (tenantId != null)
user.TenantId = tenantId.Value;
return userManager.Create(user, password);
}
Update
This is the entire AuthenticationLogic class that i use to create the user, nothings here sets the user tenantid to 6:
public class AuthenticationLogic {
public AuthenticationLogic(IOwinContext owinContext) {
userManager = owinContext.GetUserManager<ApplicationUserManager>();
}
private ApplicationUserManager userManager;
internal IdentityResult Register(string username, string email, string password, out ApplicationUser user, int? tenantId = null) {
user = new ApplicationUser {
UserName = username,
Email = email,
IsAnonymous = false,
Comment = string.Empty,
IsApproved = true,
IsLockedOut = false,
FailedPasswordAnswerAttemptCount = 0,
FailedPasswordAttemptCount = 0,
};
if (tenantId != null)
user.TenantId = tenantId.Value;
return userManager.Create(user, password);
}
}