为ASP.NET IdentityUser创建多个密钥

时间:2015-11-25 16:07:49

标签: asp.net-mvc asp.net-identity primary-key

我正在创建一个多租户应用程序(MVC)并使用Identity。在我的IdentityUser课程中,我为租户标识符添加了一个属性:

public Guid TenantId { get; set; }

默认情况下,Id属性是键(转换为数据库中的Id列)。我想将TenantId添加到主键,以便可以有多个用户具有相同的用户名,但将具有不同的TenantId。有人可以解释如何在模型类中执行此操作吗?我的示例类如下:

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 个答案:

答案 0 :(得分:0)

我找到了多种解决方案,但最终,我最终使用了这张海报的设计:

https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy