C# 自定义ASP.NET标识中的用户角色

C# 自定义ASP.NET标识中的用户角色,c#,asp.net-identity,C#,Asp.net Identity,从out或the box ASP.NET标识开始,我得到 public class ApplicationUser : IdentityUser { public int OrganisationId { get; set; } } 并进行了迁移,将此列添加到AspNetUsers表中 现在,我想维护一个组织的层次结构,使角色成员身份能够继承该层次结构 所以我要 public class ApplicationUserRole : IdentityUserRole<string&

从out或the box ASP.NET标识开始,我得到

public class ApplicationUser : IdentityUser
{
    public int OrganisationId { get; set; }
}
并进行了迁移,将此列添加到AspNetUsers表中

现在,我想维护一个组织的层次结构,使角色成员身份能够继承该层次结构

所以我要

public class ApplicationUserRole : IdentityUserRole<string>
{
    public int OrganisationId { get; set; }
    public bool Cascade { get; set; }
}
然而,这似乎是不可能的,因为IdentityUserRole不是IdentityDbContext的类型参数之一,而且似乎会在IUserRoleStore中产生各种各样的问题

是否有更好的方法来实现与ASP.NET Identity更兼容的此要求?

有三个不同的IdentityDbContext类,您正在寻找IdentityDbContext,可用于将泛型类型参数更改为自定义角色类

public class ApplicationDbContext
: IdentityDbContext<ApplicationUser, ApplicationUserRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
   /// Existing code
}
如果您只是继承并使用自定义类,那么它应该是开箱即用的,不会有任何过度的开发

相关链接:


然而,我现在不确定这是否是解决这个问题的最佳方法:也许我应该模拟谁可以单独做什么,谁可以看到什么,这样我的身份框架的实现就更接近微软的意图,因为在内部展开我的组织继承权看起来很困难。
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationUserRole, , string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
    /// Possible overrides
}