ASP.NET Core Identity: No service for role manager

前端 未结 3 550
半阙折子戏
半阙折子戏 2021-01-01 16:10

I have an ASP.NET Core app that uses Identity. It works, but when I am trying to add custom roles to the database I run into problems.

In Startup ConfigureServ

3条回答
  •  Happy的楠姐
    2021-01-01 17:02

    I was having this issue

    No service for type 'Microsoft.AspNetCore.Identity.RoleManager`

    And this page was the first result on Google. It did not answer my question, so I thought I would put my solution here, for anyone else that may be having this problem.

    ASP.NET Core 2.2

    The missing line for me was .AddRoles() in the Startup.cs file.

            services.AddDefaultIdentity()
                .AddRoles()
                .AddDefaultUI(UIFramework.Bootstrap4)
                .AddEntityFrameworkStores();
    

    Hope this helps someone

    Source: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-2.2 (at the bottom)

提交回复
热议问题