title: Cannot redirect error to custom page using Razor pages (net core 3.1)
body: <p>I am a beginner on <code>Razor</code> pages and trying to <code>Re-direct</code> all bad requests to a custom error page but it keeps giving me 500 error. I am using this document as reference.</p>
  <p><a href="https://www.learnrazorpages.com/configuration/custom-errors" rel="nofollow noreferrer">https://www.learnrazorpages.com/configuration/custom-errors</a></p>
  <p>this is what I tried:</p>
  <ol>
  <li>On my <code>Startup.cs</code> I have the following:</li>
  </ol>
  <pre><code>if (env.IsDevelopment())
  {
      app.UseDeveloperExceptionPage();
  }
  else
  {
      //app.UseExceptionHandler(&quot;/Error/{0}&quot;);
      // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
      app.UseHsts();
      app.UseStatusCodePagesWithRedirects(&quot;/Error/{0}&quot;);
  }
  </code></pre>
  <ol start="2">
  <li>My <code>Error.cshtml</code> page looks like this:</li>
  </ol>
  <pre><code>@page &quot;{id}&quot;
  @model ErrorModel
  @{
      ViewData[&quot;Title&quot;] = &quot;Error&quot;;
  }
  </code></pre>
  <ol start="3">
  <li>My <code>Error.cshtml.cs</code> look like this:</li>
  </ol>
  <pre class="lang-cs prettyprint-override"><code>public IActionResult OnGet(int id)
  {
      return Page();
  }
  
  public IActionResult OnPost(int id)
  {
      return Page();
  }
  
  public void OnGet()
  {
      RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
  }
  </code></pre>
  <p>but no matter what invalid <code>URL</code> I type in the browser it seems to re-direct to the custom page but looks like I get <code>500</code> error. Can someone point me on what I am doing wrong.</p>
  <p>thank you!</p>
  <p><a href="https://i.stack.imgur.com/sf5I1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sf5I1.png" alt="enter image description here" /></a></p>