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

标签 c# asp.net .net

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

问题:

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

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

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

关于 IdentityRole:

消息 1:

The type or namespace name 'IdentityRole' could not be found (is it missing a using directive or an assembly reference?)

消息 2:

The 'Application.Models.ApplicationRole' type can not be used as a parameter of type 'TRole' in the generic type or method 'IdentityDbContext '. There is no implicit reference conversion from 'Application.Models.ApplicationRole' to '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:

The type or namespace name 'IdentityUser' could not be found (is it missing a using directive or an assembly reference?)

消息 2:

The 'Application.Models.ApplicationUser' type can not be used as a parameter of type 'TUser' in the generic type or method 'IdentityDbContext '. There is no implicit reference conversion from 'Application.Models.ApplicationUser' to '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 是如何改变的,所以我不能再继承它们。

最佳答案

已解决。

保留这些类的包 Microsoft.AspNetCore.Identity.EntityFrameworkCore 已更改。要访问这些类(IdentityUserIdentityRole),必须添加

using Microsoft.AspNetCore.Identity;

有了这个,问题就解决了。

关于c# - 无法从 ASP.NET Core 2.0 中的 IdentityUser 和 IdentityRole 继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45830479/

相关文章:

asp.net - asp.net 中的 subsonic 是否是一个好方法?

.net - 有没有办法在文本文件中自动缩进 VB.NET 代码

c# - 验证子 ASP.NET MVC View 模型,该 View 模型在其父级中不是强制性的,但具有强制性字段

c# - 表达式 <>c__DisplayClass9 在 C# 中意味着什么

c# - 在 XAML 中使用样式从设置中绑定(bind) Drawing.Color

c# - 在消息检查器中获取操作名称?

c# - ASP.NET:我试图设置一个标签来显示图像按钮,但它没有显示页面,我该怎么做?

asp.net - 连接数据库 (MS Access) 或服务器端代码 (ASP.NET) 中的记录值

c# - 如何在 Rider IDE 中更改 .NET Framework?

c# - WCF 的非企业用途?