I'm quite new in ASP.NET Core 3.1 Razor Pages and I have a question. Hopefully you can help me further :).
What I want to have is an application with Windows AD Security. Description of what I want to do:
- Customer needs to login using his/her AD account.
- The user is authorized if entered a valid AD account/password combination.
- The user have rights to see/adjust specific pages if in a specific group, let's say if in the Administrators group of the server where the application is running on.
The problem that I have is the following. In LaunchSettings.json I have placed this code:
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:65385",
"sslPort": 44356
}
}
Then in Startup.cs I have added AddAuthentication.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddRazorPages();
}
And in the Configure part:
app.UseAuthentication();
app.UseAuthorization();
Then finally I created a separate folder, called Admin, in my Pages folder. I want to restrict this folder for only the Administrators group. So I added the Authorize to the Index1Model.
[Authorize(Roles = "Administrators")]
public class Index1Model : PageModel
{
public void OnGet()
{
}
}
Launching this code locally with IIS Express and clicking the page protected I do get the following error:
Access denied
I thought it might have to do with impersonation. But when I enable this in IIS then I cannot open the application anymore. The user which is display in the upper corner of my program is in the Administrator group and therewith should be allowed to see the page. What am I overlooking? Thanks for helping me out!