如果你看一下签名IdentityUser
(你的ApplicationUser继承自它)
public class IdentityUser<TKey, TLogin, TRole, TClaim> : IUser<TKey>
where TLogin : Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<TKey>
where TRole : Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole<TKey>
where TClaim : Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim<TKey>
{
}
你可以看到它接受你的自定义定义IdentityUserRole
.
你的班MyApplicationUser
你必须实现必须实现正确的类型:
public class MyApplicationUser : IdentityUser<string, MyUserLogin, ApplicationUserRoles, MyUserClaim>
{
}
以及你的角色:
public class MyRole : IdentityRole<string, ApplicationUserRoles>
{
}
和你的ApplicationDbContext
:
public class MyContext : IdentityDbContext<MyUser, MyRole, string, MyUserLogin, ApplicationUserRoles, MyUserClaim>
{
}
和你的UserStore
:
public class MyUserStore: UserStore<MyUser, MyRole, string, MyUserLogin, ApplicationUserRoles, MyUserClaim>
{
public MyUserStore(MyContext context)
: base(context)
{
}
}
我想应该是这样。有一个githubrepo https://github.com/Leftyx/ASP.NET-Identity-2.x我在那里玩了一下自定义类和自定义表名称。