Store does not implement IUserRoleStore ASP.NET Core Identity

后端 未结 3 1136
孤街浪徒
孤街浪徒 2021-02-19 03:04

I\'m using ASP.NET Core 2.1 Identity. I\'ve overridden IdentityUser because I need to add some additional properties on the user.

In Startup.cs

servic         


        
3条回答
  •  执笔经年
    2021-02-19 03:18

    For there are not any answers about the solution in asp.net Core 2.2, I would like to share the same error I meet in asp.net Core 2.2

    First, here is another solution for the same error in asp.net core 2.1 https://github.com/aspnet/AspNetCore.Docs/issues/8683

    And thanks to the author's idea, I meet the problem when I follow the official guidance in asp.net core 2.2 (the url is in here : MicrosoftDocs For asp.net core 2.2). When I finish the step he says and try to run the project, it throws a exception "Store does not implement IUserRoleStore"

    and the problem is : actually, this is the sample for asp.net core 2.1 (And I strongly doubt that why the Microsoft will provide users a docs with not any sample codes, which can't make sense probably)

    And you will find that, in Areas/Identity/Data/IdentityHostingStartup.cs IdentityHostingStartup::Configure method you have the following codes :

    services.AddDefaultIdentity().AddEntityFrameworkStores();
    

    which is same as the code you should add in /Program.cs ConfigureService as the step : Add Role services to Identity in docs mentioned :

    services.AddDefaultIdentity().AddRoles().AddEntityFrameworkStores();
    

    so if you meet the same problem in asp.net core 2.2, an alternative solution is :

    1. Following the docs in asp.net 2.2
    2. When you meet this Chapter : Add Role services to Identity , just ignore the official docs and do it :

    replace the row

    services.AddDefaultIdentity().AddEntityFrameworkStores();
    

    with

    services.AddDefaultIdentity().AddRoles().AddEntityFrameworkStores();
    

    in Areas/Identity/Data/IdentityHostingStartup.cs IdentityHostingStartup::Configure method, but not add it in program.cs (the file can't be deleted in asp.net core 2.2)

    The project I use Asp.net Identity will be updated later in my repos : UWPHelper , Good Luck :)

提交回复
热议问题