I\'ve created a test project using:
dotnet new razor --auth Individual --output Test
This creates a Startup.cs that contains:
p
In addition to the answers already provided, despite adding .AddRoles
, I still could not get Authorization when use Authorize(Roles = "Administrator")
on my controllers. For some reason,the "role claim doesn't seem to affect IsUserInRole or AuthorizeAttribute with a role name."
To make use of roles I would suggest that one use the ASP.NET 2.0 way like below:
services.AddIdentity()
.AddDefaultUI()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores();
This way, you get to use your roles and also get the Identity pages scaffolded for you.
Refer to this issue on aspnet github: Issue 1813