How to add custom roles to ASP.NET Core

前端 未结 3 1655
暗喜
暗喜 2021-02-04 11:11

I\'ve found this answer but it doesn\'t seem to fit in my ASP Net Core project.

Things I am trying to understand:

  • How can I add a custom role. I\'ve even l
3条回答
  •  清歌不尽
    2021-02-04 11:24

    Adding to Temi's answer and Xavier's comment to it, my experience with this was a little different using asp.net-core-2.

    In order to get this working I had to add the IServiceProvider as a parameter of the Configure method to get an instance of it.

    public void Configure(
        IApplicationBuilder App,
        IHostingEnvironment Env,
        ILoggerFactory LoggerFactory,
        IServiceProvider ServiceProvider
    )
    {
        /* trimmed */
    
        CreateRoles(ServiceProvider).Wait();
    }
    

提交回复
热议问题