gem*_*n01 6 asp.net-identity asp.net-core asp.net-core-identity
我通过迁移创建了表,以使用 ASP.NET Core 标识管理我的 ASP.NET Core 项目的安全性。
我需要能够在AspNetUserRoles表中插入一个额外的字段,以便以不同的方式管理已经与 ADMIN 角色关联的用户。
例如,我有与美国相关联的 ADMIN 和与另一个巴西或与意大利相关联的 ADMIN 国家相关联的 ADMIN,但他们的真正角色始终是 ADMIN。
实际上,当我将用户与 ADMIN 角色关联时,只需添加一个属性即可。
在 AspNetUserRoles 表中具有自定义列的 ASP.NET Core 标识表
我试图以IdentityUserRole这种方式扩展类:
public class AspNetUserRoles : IdentityUserRole<string>
{
    public string Nation { get; set; }
}
但是当我在迁移类中启动迁移脚本(代码优先)时,没有检测到任何变化!
PM> Add-Migration aspnetuserrolesupdate -Context ApplicationDbContext
这是结果:
public partial class aspnetuserrolesupdate : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
    }
    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}
正如您从产品代码中看到的,没有发现任何变化......
在项目中,我已经插在领域AspNetUsers和AspNetRoles表成功地以这种方式,但我怎么能第三列添加到AspNetUserRoles表?
谢谢你们
我是这样解决的:
我修改了注入的类,将它们全部添加到 ApplicationUserRole 可用
public class ApplicationDbContext: // IdentityDbContext <ApplicationUser, ApplicationRole, string>
     IdentityDbContext <
     ApplicationUser, ApplicationRole, string,
     IdentityUserClaim <string>, ApplicationUserRole, IdentityUserLogin <string>,
     IdentityRoleClaim <string>, IdentityUserToken <string>>
{
     public ApplicationDbContext (DbContextOptions <ApplicationDbContext> options)
         : base (options)
     {
     }
}
| 归档时间: | 
 | 
| 查看次数: | 968 次 | 
| 最近记录: |