【问题标题】:Add new IdentityRole添加新的身份角色
【发布时间】: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


【解决方案1】:

您似乎尝试在没有依赖注入的情况下使用 aspnet 身份。请参阅official docs 如何使用 aspnet 核心配置身份。

【讨论】:

    猜你喜欢
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2011-07-15
    • 2013-08-19
    • 1970-01-01
    • 2014-08-08
    相关资源
    最近更新 更多