I\'ve created a test project using:
dotnet new razor --auth Individual --output Test
This creates a Startup.cs that contains:
p
Starting in .Net Core 2.1, AddDefaultIdentity is the same as calling:
AddIdentityAddDefaultUIAddDefaultTokenProvidersTo add role functionality, go to Startup.cs under ConfigureServices you can use .AddRoles like so:
services.AddDefaultIdentity()
.AddRoles() //<-- This line
.AddEntityFrameworkStores();
That's all that is needed. It is crucial to logout and login again.
For the record (and just to test), I tried services.AddIdentity:
IServiceCollection does not contain a defintion for 'AddIdentity'...
and services.AddIdentityCore (no error until Debug and displaying the page):
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action configureOptions).
There may be more you can do to get the latter two working, but the code I posted for AddDefaultIdentity is all I needed in order to get User.IsInRole and other role functionality working in .NET Core 2.1 (and 3.1).