基于Asp.net核心角色的访问身份/角色使用户表自引用

问题描述 投票:0回答:1

嗨,我正在尝试对访问控制系统进行建模,在该系统中,角色通过角色授予对某些操作的访问权限。我正在尝试使用具有身份和角色的asp.net核心。似乎默认身份带有用于用户的自己的表。我必须要自我引用用户表,因为用户将具有同时也是用户的经理。

是否可以使身份附带的默认表做到这一点?

c# asp.net-core asp.net-identity roles rbac
1个回答
0
投票

如果要向现有的IdentityUser添加其他属性,您要做的就是继承IdentityUser类,然后添加自己的属性,然后转到启动文件和dbcontext并执行以下操作

public class InheritedUser : IdentityUser
{
   public bool HasTwoHeads { get; set;}

}

您的启动

services.AddDefaultIdentity<InheritedUser>()
                .AddEntityFrameworkStores<CustomDbContext>()                               .AddDefaultTokenProviders()
.AddDefaultUI(Microsoft.AspNetCore.Identity.UI.UIFramework.Bootstrap4);

然后是您继承的DbContext

public class InheritedDbContext : IdentityDbContex<InheritedUser>
{

}
© www.soinside.com 2019 - 2024. All rights reserved.