[英]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.