简体   繁体   English

在MVC 5点网身份中扩展IdentityUserRole后,UserManager.GetRoles不起作用

[英]UserManager.GetRoles doesn't work after extending the IdentityUserRole in MVC 5 Dot Net Identity

I have extended the IdentityUserRole by adding a foreign key column and now I am unable to Authorize or retrieve Roles information. 我通过添加外键列扩展了IdentityUserRole,但现在我无法授权或检索角色信息。 Could please anyone help me in sorting out this issue. 请任何人帮助我解决此问题。

My IdentityUserRole has a foreign key column from AspNetApplications table and the IdentityUserRole extension is as follow 我的IdentityUserRole在AspNetApplications表中有一个外键列,并且IdentityUserRole扩展如下

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

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

After adding the migration I can see the foreign key column is created in AspNetUserRoles table. 添加迁移后,我可以看到在AspNetUserRoles表中创建了外键列。 A screen shot of the table is as follow 该表的屏幕截图如下

在此处输入图片说明

Here I have two questions to ask 在这里我有两个问题要问

  1. Why it has created an auto Discriminator column and how I can remove it, if it has any overhead. 为什么创建了自动鉴别符列,以及如何删除它(如果有任何开销)。
  2. What extra I have to do in order to get my Authorization and UserManager.GetRoles working as they were before doing this extension. 为了使Authorization和UserManager.GetRoles在进行此扩展之前能够正常工作,我还需要做些什么。

Discriminator column is about Table per Hierarchy (TPH).refer to this link What is a Discriminator column in ASP.NET Migrations? “鉴别符”列与“按层次结构表(TPH)”有关。请参考此链接。ASP.NET 迁移中的“鉴别符”列是什么?

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. 关于身份验证您的区分符列应该有问题。例如,这段代码UserManager.GetRoles()具有Discriminator的where子句,用于获取数据。

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

I think your where clause value in select command which send to database is different from what value you have in database 我认为发送到数据库的select命令中的where子句值与数据库中的值不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM