How to use Roles in ASP.NET Core 2.1?

后端 未结 5 2234
小蘑菇
小蘑菇 2021-02-12 20:31

I\'ve created a test project using:

dotnet new razor --auth Individual --output Test

This creates a Startup.cs that contains:

p         


        
5条回答
  •  盖世英雄少女心
    2021-02-12 20:44

    It seems that finally Microsoft understood that not every application needs roles and separated them.

    Notice that AddDefaultIdentity is declared as:

    public static IdentityBuilder AddDefaultIdentity(this IServiceCollection services) where TUser : class;
    

    So, you can continue to configure Identity options through that IdentityBuilder. What you want to do is:

    services.AddDefaultIdentity().AddRoles();
    

    Fortunately, they also removed the IUser and IRole constrains, so now you can use models in a completely separate assembly without having to install hundreds of NuGet packages.

提交回复
热议问题