我正在尝试向 ASP.NET Core Identity 系统添加一个新角色。但到目前为止还没有运气。
代码:C#
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
private ApplicationDbContext _context;
var roleStore = new RoleStore<IdentityRole>(_context);
var roleManager = new RoleManager<IdentityRole>(roleStore); // <============ Problem
await roleManager.CreateAsync(new IdentityRole("Somevalue"));
错误信息:
错误 CS7036 没有给出与“RoleManager.RoleManager(IRoleStore, IEnumerable>, ILookupNormalizer, IdentityErrorDescriber, ILogger>, IHttpContextAccessor) 的所需形式参数“roleValidators”相对应的参数
.net 4.6 VB.net 中的相同代码有效
Dim roleManager = New RoleManager(Of IdentityRole)(New RoleStore(Of IdentityRole))
Dim newRoleName As String = "Some groupname"
If Not roleManager.RoleExists(newRoleName) Then
Dim role = New IdentityRole()
role.Name = newRoleName
roleManager.Create(role)
End If