在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后,UserManager.GetRoles 不起作用

UserManager.GetRoles doesn#39;t work after extending the IdentityUserRole in MVC 5 Dot Net Identity(在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后,UserManager.GetRoles 不起作用)
本文介绍了在 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. 为了让我的 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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)