Passing a view model with Server.TransferRequest()
<p>I'm trying to fine-tune the error handling in my MVC application.</p>

<p>I've enabled custom errors in my <em>web.config</em>, and I added the following code to <code>Application_Error</code>.</p>

<p><strong>Global.asax</strong></p>

<pre><code>protected void Application_Error(object sender, EventArgs e)
{
    Exception exception = Server.GetLastError() as Exception;
    if (exception != null)
    {
        Context.ClearError();
        Context.Response.TrySkipIisCustomErrors = true;

        string path = (exception is HttpException &amp;&amp; (exception as HttpException).GetHttpCode() == 404) ?
            "~/Error/NotFound" :
            "~/Error/Index";
        Context.Server.TransferRequest(path, false);
    }
}
</code></pre>

<p><strong>ErrorController.cs</strong></p>

<pre><code>[AllowAnonymous]
public ActionResult Index()
{
    Response.Clear();
    Response.StatusCode = 503;
    Response.TrySkipIisCustomErrors = true;
    return View();
}

[AllowAnonymous]
public ActionResult NotFound()
{
    Response.Clear();
    Response.StatusCode = 404;
    Response.TrySkipIisCustomErrors = true;
    return View();
}
</code></pre>

<p><strong>Web.config</strong></p>

<pre class="lang-xml prettyprint-override"><code>&lt;system.web&gt;
  &lt;customErrors mode="RemoteOnly" defaultRedirect="~/Error"&gt;
    &lt;error statusCode="404" redirect="~/Error/NotFound"/&gt;
    &lt;error statusCode="500" redirect="~/Error" /&gt;
  &lt;/customErrors&gt;
&lt;/system.web&gt;
</code></pre>

<p>This seems to be working fairly well. But how can I pass some error details along to my Error controller?</p>

<p>Also, extra points for tips on getting exception details to my Error controller for exceptions that occur within a controller.</p>

<p><em>Note: I do not want to use a redirect here. Doing so would tell crawlers like Google incorrect information about the URL.</em></p>