title: ASP.NET Core 3.1 - Access denied
body: <p>I'm quite new in ASP.NET Core 3.1 Razor Pages and I have a question. 
  Hopefully you can help me further :). </p>
  
  <p>What I want to have is an application with Windows AD Security. 
  Description of what I want to do:</p>
  
  <ul>
  <li>Customer needs to login using his/her AD account.</li>
  <li>The user is authorized if entered a valid AD account/password combination.</li>
  <li>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.</li>
  </ul>
  
  <p>The problem that I have is the following.
  In LaunchSettings.json I have placed this code:</p>
  
  <pre><code>    "windowsAuthentication": true,
      "anonymousAuthentication": false,
      "iisExpress": {
        "applicationUrl": "http://localhost:65385",
        "sslPort": 44356
      }
    } 
  </code></pre>
  
  <p>Then in Startup.cs I have added AddAuthentication.</p>
  
  <pre><code>    public void ConfigureServices(IServiceCollection services)
      {
        services.AddAuthentication(IISDefaults.AuthenticationScheme);
        services.AddRazorPages();
      }
  </code></pre>
  
  <p>And in the Configure part:</p>
  
  <pre><code>      app.UseAuthentication();
        app.UseAuthorization();
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>  [Authorize(Roles = "Administrators")]
    public class Index1Model : PageModel
      {
          public void OnGet()
          {
          }
      }
  </code></pre>
  
  <p>Launching this code locally with IIS Express and clicking the page protected I do get the following error:</p>
  
  <pre><code>Access denied
  </code></pre>
  
  <p>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!</p>