title: Display custom error page and show exception details
body: <p>I have a custom Errors controller that looks like this:</p>
  
  <pre><code>public class ErrorsController : BaseController
  {
      public ActionResult RaiseError(string error = null)
      {
          string msg = error ?? "An error has been thrown (intentionally).";
          throw new Exception(msg);
      }
  
      public ActionResult Error404()
      {
          Response.TrySkipIisCustomErrors = true;
          Response.StatusCode = (int)HttpStatusCode.NotFound;
          return View();
      }
  
      public ActionResult Error500()
      {
          Response.TrySkipIisCustomErrors = true;
  
          var model = new Models.Errors.Error500()
          {
              ServerException = Server.GetLastError(),
              HTTPStatusCode = Response.StatusCode
          };
  
          return View(model);
      }
  }
  </code></pre>
  
  <p>My Errors500.cshtml looks like this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;Error500&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          An internal error has occurred.
              @if (Model != null &amp;&amp; Model.ServerException != null &amp;&amp;                 HttpContext.Current.IsDebuggingEnabled)
      {
          &lt;div&gt;
              &lt;p&gt;
                  &lt;b&gt;Exception:&lt;/b&gt; @Model.ServerException.Message&lt;br /&gt;
              &lt;/p&gt;
              &lt;div style="overflow:scroll"&gt;
                  &lt;pre&gt;
                      @Model.ServerException.StackTrace
                  &lt;/pre&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      }
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and my web.config has my error handlers specified as such:</p>
  
  <pre><code>&lt;system.webServer&gt;
  &lt;httpErrors errorMode="Custom" existingResponse="Replace" &gt;
    &lt;remove statusCode="404" subStatusCode="-1" /&gt;
    &lt;error statusCode="404" subStatusCode="-1" responseMode="ExecuteURL" path="/Errors/Error404" /&gt;
    &lt;remove statusCode="500" subStatusCode="-1" /&gt;
    &lt;error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/Errors/Error500" /&gt;
  &lt;/httpErrors&gt;
  </code></pre>
  
  <p>The problem is: everytime I call /errors/raiseerror to test my 500 handling; I'm redirected to errors/error500 (fine). However, the exception data isn't rendered on the page because the Server.GetLastError() call returns null instead of the exception thrown by RaiseError().</p>
  
  <p>What's the best way to handle a custom 500 error page where that custom page can render out the exception details as well?</p>