title: Razor custom error page ignores it's OnGet handler
body: <p>There is custom error page:</p>
  
  <pre><code>public sealed class ErrorModel : PageModel
  {
      public ErrorModel()
      {
         // app stops at breakpoint inside ctor
      }
  
      public IActionResult OnGet()
      {
          // app doesn't stop here, why?
  
          // this is for debugging purposes only
          return BadRequest();
      }
  }
  </code></pre>
  
  <p>and its view:</p>
  
  <pre><code>@page
  @model ErrorModel
  
  @if (Model != null)
  {
      &lt;p&gt;
          The error page.
      &lt;/p&gt;
  }
  </code></pre>
  
  <p>Page is registered in usual way:</p>
  
  <pre><code>app.UseExceptionHandler("/Error");
  </code></pre>
  
  <p>When application redirects to error page, it stops on breakpoints inside page constructor and page view, but ignores code inside <code>OnGet</code>. Since app doesn't call my <code>OnGet</code>, page renders without any useful data I fill inside <code>OnGet</code>.</p>
  
  <p>All breakpoints are enabled - I'm debugging actual code.</p>
  
  <p>Any idea what's happening and how to solve this?</p>
  
  <p><strong>UPD</strong></p>
  
  <p>I've reduced the page model code and the view.
  When app stops at this line:</p>
  
  <p><code>@if (Model != null)</code></p>
  
  <p>the call stack is:</p>
  
  <blockquote>
    <p>Portal.App.Views.dll!Portal.Pages.Pages_Error.ExecuteAsync() Line 4 C#
        Microsoft.AspNetCore.Mvc.RazorPages.dll!Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAdapter.ExecuteAsync()  Unknown
        Microsoft.AspNetCore.Mvc.Razor.dll!Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, Microsoft.AspNetCore.Mvc.Rendering.ViewContext context) Unknown
        Microsoft.AspNetCore.Mvc.Razor.dll!Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, Microsoft.AspNetCore.Mvc.Rendering.ViewContext context, bool invokeViewStarts)  Unknown
        Microsoft.AspNetCore.Mvc.Razor.dll!Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext context) Unknown
        Microsoft.AspNetCore.Mvc.ViewFeatures.dll!Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, string contentType, int? statusCode)  Unknown
        Microsoft.AspNetCore.Mvc.RazorPages.dll!Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageResultExecutor.ExecuteAsync(Microsoft.AspNetCore.Mvc.RazorPages.PageContext pageContext, Microsoft.AspNetCore.Mvc.RazorPages.PageResult result)  Unknown
        Microsoft.AspNetCore.Mvc.RazorPages.dll!Microsoft.AspNetCore.Mvc.RazorPages.PageResult.ExecuteResultAsync(Microsoft.AspNetCore.Mvc.ActionContext context)   Unknown</p>
  </blockquote>
  
  <p>So, app executes <code>PageResult</code>. Where this result comes from?</p>
  
  <p><strong>UPD 2</strong></p>
  
  <p>This looks like authentication issue. When user is authenticated, everything works as expected. But for non-authenticated users my <code>OnGet</code> isn't called. <code>ErrorModel</code> hasn't <code>Authorize</code> attribute. How authentication affects this?</p>
  
  <p>I've no any custom authentication config, so, I assume defaults are used:</p>
  
  <pre><code>    private void ConfigureMvcServices(IServiceCollection services)
      {
          services
              .AddMvc()
              // another services;
      }
  </code></pre>
  
  <p>Error page is in the <code>Pages</code> folder - <code>Pages/Error</code>.</p>
  
  <p>Besides, if user is not authenticated, and page requires authentication, 401 must be returned, isn't it?</p>