title: How to use UseExceptionHandler in the mvc startup without redirecting the user?
body: <p>I have a ASP.NET Core 2.1 MVC application, and I'm trying to return a separate html view when an exception occurs. The reason for this is that if there are errors, we don't want google to register the redirects to the error page for our SEO (I've omitted development settings to clear things up).</p>
  
  <p>Our startup contained this:</p>
  
  <pre><code>app.UseExceptionHandler("/Error/500"); // this caused a redirect because some of our middleware.
  app.UseStatusCodePagesWithReExecute("/error/{0}"); 
  </code></pre>
  
  <p>But we want to prevent a redirect, so we need to change the UseExceptionHandler. 
  I've tried to use the answer from this <a href="https://stackoverflow.com/a/40615253/1829773">question</a> like below:</p>
  
  <pre><code>app.UseExceptionHandler(
              options =&gt;
              {
                  options.Run(
                      async context =&gt;
                      {
                          context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                          context.Response.ContentType = "text/html";
                          await context.Response.WriteAsync("sumtin wrong").ConfigureAwait(false);
  
                      });
              });
  </code></pre>
  
  <p>But this gives a very ugly page without any styling. Another solution we've tried to use is creating an error handling middle ware, but there we run into the same problem there where we can't add a view.</p>
  
  <p>How can I return a styled view in case of an exception, without redirecting the user?</p>
  
  <p>EDIT: the UseExceptionHandler doesn't cause a redirect, it was caused by a bug in some of our middleware. </p>