简体   繁体   English

Net Core:找不到类型或命名空间名称“RoleProvider”

[英]Net Core: Type or namespace name 'RoleProvider' could not be found

I am migrating a project from .Net 4.6.2 into .Net Core 2.0. 我正在将项目从.Net 4.6.2迁移到.Net Core 2.0。 What is the replacement for RoleProvider in Net Core? Net Core中RoleProvider的替代品是什么?

The type or namespace name 'RoleProvider' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称“RoleProvider”(您是否缺少using指令或程序集引用?)

 public class CustomerRoleProvider : RoleProvider
    {
        public override string CustomerName { get; set; }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {

New code looks like this, received error 新代码看起来像这样,收到错误

Using the generic type 'RoleManager<TRole>' requires 1 type arguments

// Error first line: Using the generic type 'RoleManager<TRole>' requires 1 type arguments

public class CustomerRoleProvider : RoleManager
{
    public string ApplicationName { get; set; }

    public void CreateRole(IServiceProvider serviceProvider, string roleName)
    {
        var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
        throw new NotImplementedException();
    }

Update: Answer from John Kenney looks great, hopefully someone can add more into his answer as edit. 更新: John Kenney的回答看起来很棒,希望有人可以在他的回答中添加更多内容作为编辑。

RoleProvider doesn't exist in .NET Core at least not in that form. RoleProvider在.NET Core中不存在,至少不是那种形式。 I believe what you are looking for is the RoleManager . 我相信你要找的是RoleManager The implementation is quite similar to the below: 实现与以下内容非常相似:

var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
var UserManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();

Kindly refer to this article for detail on how to implement it. 请参阅本文以获取有关如何实现它的详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 网络核心:找不到类型或名称空间名称“ GlobalFilterCollection” - Net Core: Type or namespace name 'GlobalFilterCollection' could not be found 将 .Net Core 项目从 3.1 降级到 2.2 - 找不到类型或命名空间名称“IWebHostEnvironment” - Downgrade .Net Core project from 3.1 to 2.2 - The type or namespace name 'IWebHostEnvironment' could not be found 使用 .NET Core Fakes 和 VS 2019 Preview 6.9.0 Preview 2.0 找不到类型或命名空间名称 - The type or namespace name could not be found with .NET Core Fakes and VS 2019 Preview 6.9.0 Preview 2.0 ASP.NET 核心 - 错误 CS0246 找不到类型或命名空间名称“ApplicationUserRole&lt;&gt;” - ASP.NET Core - Error CS0246 The type or namespace name 'ApplicationUserRole<>' could not be found “ASP.NET Core 1.0 RC2中找不到”类型或命名空间名称“ - “The type or namespace name could not be found” in ASP.NET Core 1.0 RC2 无法构建.Net core 2.2项目? 找不到类型或名称空间名称“系统” - Cannot build .Net core 2.2 project? The type or namespace name 'System' could not be found 在DNX Core 5.0中找不到类型或命名空间名称“RNGCryptoServiceProvider” - The type or namespace name 'RNGCryptoServiceProvider' could not be found in DNX Core 5.0 在.Net Core应用中找不到类型或名称空间“系统” - The type or namespace 'system' could not be found in .Net Core app 找不到类型或名称空间名称 - Type or namespace name could not be found 找不到类型或名称空间名称 - Type or namespace name could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM