【问题标题】:Asp.net core role based access identity / roles make user table self referencingAsp.net core 基于角色的访问身份/角色使用户表自引用
【发布时间】:2020-04-29 00:37:59
【问题描述】:

您好,我正在尝试对访问控制系统进行建模,其中通过角色授予对某些操作的访问权限。我正在尝试将 asp.net 核心与身份和角色一起使用。似乎默认身份带有自己的用户表。我拥有的用户表需要自我引用,因为用户将拥有也是用户的经理。

是否可以让标识自带的默认表做到这一点?

【问题讨论】:

    标签: c# asp.net-core asp.net-identity roles rbac


    【解决方案1】:

    如果您想为已经存在的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>
    {
    
    }
    

    【讨论】:

    • 这对我不起作用。当我尝试访问 InheritedUser 时,它始终为空。是的,有一个数据对象,但它不包含任何用户信息
    • 在我的 _layout.cshtml 我有 /@inject ApplicationUser applicationUser /@inject SignInManager signInManager;我还有 /@if ( this.User.IsSysAdmin ( signInManager , applicationUser ) ){} 指向 Identityextension.IsSysAdmin() 应用程序用户没有填写任何有意义的内容。它填写了几个 guid,但它不是正确的信息,其他一切都是空的。 ApplicationUser applicationUser 没有被填充
    猜你喜欢
    • 2018-09-06
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2015-04-09
    • 2014-07-27
    • 1970-01-01
    相关资源
    最近更新 更多