无法从ASP.NET Core 2.0中的IdentityUser和IdentityRole继承

问题描述 投票:15回答:5

我正在尝试完成对.NET Core 2.0的更新,但会弹出几个错误:

问题:

我有两个类,ApplicationRole和ApplicationUser,它们从IdentityRole和IdentityUser继承一些属性。

随着Core 2.0的更新,我收到以下错误,声称找不到IdentityRole和IdentityUser。

但是,包Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.0已安装在新版本的.NET Core中

关于IdentityRole:

消息1:

找不到类型或名称空间名称'IdentityRole'(是否缺少using指令或程序集引用?)

消息2:

'Application.Models.ApplicationRole'类型不能用作通用类型或方法'IdentityDbContext'中类型'TRole'的参数。没有从'Application.Models.ApplicationRole'到'Microsoft.AspNetCore.Identity.IdentityRole'的隐式引用转换。

ApplicationRole的定义:

public class ApplicationRole:IdentityRole
{
    public string Description { get; set; }
    public DateTime CreatedDated { get; set; }
    public string IPAddress { get; set; }
}

关于IdentityUser:

消息1:

找不到类型或名称空间名称'IdentityUser'(是否缺少using指令或程序集引用?)

消息2:

'Application.Models.ApplicationUser'类型不能用作通用类型或方法'IdentityDbContext'中类型'TUser'的参数。没有从'Application.Models.ApplicationUser'到'Microsoft.AspNetCore.Identity.IdentityUser'的隐式引用转换。

ApplicationUser的定义

public class ApplicationUser:IdentityUser
{
    public string Name { get; set; }
}

下面定义此类的指南及其用法:

http://www.c-sharpcorner.com/article/asp-net-core-mvc-authentication-and-role-based-authorization-with-asp-net-core/

随着对Core 2.0的更改,我想知道IdentityRole和IdentityUser是如何更改的,因此我不再可以从它们那里继承。

c# asp.net .net
5个回答
19
投票
已解决。

7
投票
ICollection<IdentityUserRole<int>> RolesICollection<IdentityUserClaim<int>> ClaimsICollection<IdentityUserLogin<int>> Logins导航属性已从Microsoft.AspNetCore.Identity.IdentityUser中删除。

4
投票
对我来说,通过安装软件包已解决:

2
投票
这发生在我身上,但我将Asp.net Core与传统.NET Framework结合使用。您需要添加Nuget程序包Microsoft.Extensions.Identity。包含类IdentityUserIdentityRole

0
投票
您需要安装Microsoft.AspNetCore.Identity.EntityFramework软件包
© www.soinside.com 2019 - 2024. All rights reserved.