UserManager.GetRoles doesn#39;t work after extending the IdentityUserRole in MVC 5 Dot Net Identity(在 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
这里有两个问题要问
- 为什么它创建了一个自动鉴别器列以及如何删除它,如果它有任何开销.
- 为了让我的 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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MVC 5 Dot Net Identity 中扩展 IdentityUserRole 后,UserManager.GetRoles 不起作用
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01