UserManager.GetRoles 在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后不起作用 [英] UserManager.GetRoles doesn't work after extending the IdentityUserRole in MVC 5 Dot Net Identity

查看:20
本文介绍了UserManager.GetRoles 在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过添加外键列扩展了 IdentityUserRole,现在我无法授权或检索角色信息.可以请任何人帮助我解决这个问题.

I have extended the IdentityUserRole by adding a foreign key column and now I am unable to Authorize or retrieve Roles information. Could please anyone help me in sorting out this issue.

我的 IdentityUserRole 有一个来自 AspNetApplications 表的外键列,IdentityUserRole 扩展如下

My IdentityUserRole has a foreign key column from AspNetApplications table and the IdentityUserRole extension is as follow

public class AspNetUserRoles : IdentityUserRole
{
    [Key]
    public string ApplicationId { get; set; }

    [ForeignKey("ApplicationId")]
    public AspNetApplications AspNetApplications { get; set; }
}

添加迁移后,我可以看到在 AspNetUserRoles 表中创建了外键列.表格截图如下

After adding the migration I can see the foreign key column is created in AspNetUserRoles table. A screen shot of the table is as follow

这里我有两个问题要问

  1. 为什么它创建了一个自动鉴别器列以及我如何删除它(如果它有任何开销).
  2. 为了让我的 Authorization 和 UserManager.GetRoles 像在做这个扩展之前一样工作,我还需要做些什么.

推荐答案

Discriminator 列是关于 Table per Hierarchy (TPH).参考此链接 ASP.NET 迁移中的鉴别器列是什么?

Discriminator column is about Table per Hierarchy (TPH).refer to this link What is a Discriminator column in ASP.NET Migrations?

关于您的身份验证 您的鉴别器列应该有问题.例如,此代码 UserManager.GetRoles() 具有用于提取数据的鉴别器的 where 子句.

About your authentication It should be something wrong with your dicriminator column.for example this code UserManager.GetRoles() has where clause for Discriminator filed to fetch data.

SELECT [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Roles] AS [Extent1]
WHERE [Extent1].[Discriminator] = N'Role'

我认为发送到数据库的 select 命令中的 where 子句值与数据库中的值不同

I think your where clause value in select command which send to database is different from what value you have in database

这篇关于UserManager.GetRoles 在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆