Identity中扩展IdentityUserRole后

Identity中扩展IdentityUserRole后

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

问题描述

我已经通过添加一个外键列扩展了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. 为了让我的授权和UserManager.GetRoles在执行此扩展之前,我需要执行哪些额外的操作。


推荐答案

Discriminator列是关于Table per Hierarchy(TPH)。请参考这个链接

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

关于你的身份验证你的dicriminator列应该是错误的,例如这个代码UserManager.GetRoles()有wh Discriminator提交的ere条款提取数据。

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

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

07-31 10:37