【发布时间】:2017-01-07 16:40:01
【问题描述】:
我正在尝试向 ASP.NET Core 身份系统添加一个新角色。 但到目前为止还没有运气。
代码: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
【问题讨论】:
-
你能发布你的
Startup.cs代码相关的aspnet身份吗?
标签: c# asp.net entity-framework-6 asp.net-core asp.net-core-identity