Reputation: 4229
I am creating a multi-tenant application (MVC) and am using Identity. In my IdentityUser
class, I added a property for the tenant identifier:
public Guid TenantId { get; set; }
By default, the Id property is the key (translates to the Id column in the database). I want to add TenantId to the primary keys so that there can be multiple users with the same username, but will have different TenantId's. Can someone explain how to do this in the model class? My example class below:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public Guid TenantId { get; set; }
}
Upvotes: 2
Views: 276
Reputation: 4229
I found multiple solutions, but ultimately, I ended up using this poster's design:
https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy
Upvotes: 1