无法继承ASP.NET Core 2.0中的IdentityUser和IdentityRole [英] Can't inherit from IdentityUser and IdentityRole in ASP.NET Core 2.0

查看:92
本文介绍了无法继承ASP.NET Core 2.0中的IdentityUser和IdentityRole的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

问题:

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

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

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

关于IdentityRole:

消息1:

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

消息2:

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

ApplicationRole的定义:

 公共类ApplicationRole:IdentityRole{公共字符串说明{放;}公开的DateTime创建的日期{放;}公用字符串IPAddress {get;放;}} 

关于IdentityUser:

消息1:

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

消息2:

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

ApplicationUser的定义

 公共类ApplicationUser:IdentityUser{公共字符串名称{get;放;}} 

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

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 的程序包已更改.要访问这些类别( IdentityUser IdentityRole ),必须添加

 使用Microsoft.AspNetCore.Identity; 

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

I'm trying to finish updating to .NET Core 2.0 but a couple of errors pop up:

The problem:

I have two classes, ApplicationRole and ApplicationUser which inherit some properties from IdentityRole and IdentityUser.

With the update to Core 2.0 I'm getting the following errors, claiming that IdentityRole and IdentityUser could not be found.

However, the package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.0 is installed in the new version of .NET Core

About IdentityRole:

Message 1:

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

Message 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 '.

Definition of ApplicationRole:

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

About IdentityUser:

Message 1:

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

Message 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 '.

Definition of ApplicationUser

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

The guide followed to define this classes and their use are here:

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

With the change to Core 2.0 I wonder how IdentityRole and IdentityUser changed so I can no longer inherit from them.

解决方案

Solved.

The package that was keeping those classes Microsoft.AspNetCore.Identity.EntityFrameworkCore changed. To access those clases (IdentityUser and IdentityRole) one must add

using Microsoft.AspNetCore.Identity;

With this, the problem is gone.

这篇关于无法继承ASP.NET Core 2.0中的IdentityUser和IdentityRole的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆