ASP.NET Core Identity: No service for role manager

前端 未结 3 551
半阙折子戏
半阙折子戏 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条回答
  •  天命终不由人
    2021-01-01 17:12

    What am I doing wrong? My gut says there's something wrong with how I add the RoleManager as a service.

    The registration part is actually fine, tho' you should remove services.AddScoped>(), as the role manager is already added for you by services.AddIdentity().

    Your issue is most likely caused by a generic type mismatch: while you call services.AddIdentity() with IdentityRole, you try to resolve RoleManager with IdentityRole, which is an equivalent of IdentityRole (string being the default key type in ASP.NET Core Identity).

    Update your Configure method to take a RoleManager> parameter and it should work.

提交回复
热议问题