2

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; }
}

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.