我有一个后端网站(ASP.NET MVC),它有自己的tenantId(ASP.NET身份),这个网站可以为其他网站创建用户自己的tenantId(所有租户都在同一个数据库中)。
问题是,当我使用Create
中的ApplicatoinUserManager
方法时ApplicationUser
即使我将TenantId对应于用户所属的网站,也会使用TenantId创建用户我的后端网站。
为什么会这样?
以下是用户的注册码:
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);
}
更新
这是我用来创建用户的整个AuthenticationLogic类,这里没有设置用户tenantid为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);
}
}