title: Displaying custom error CSHTML page in MVC5 on 404 / 500 / any exception?
body: <p>I have been pulling my hair out over this all day.  I'm trying to just display a friendly cshtml page whenever an exception is thrown so my UX is consistent - I don't want my users even knowing I'm on the .net stack from the UI, ever.  </p>
  
  <p>I'm testing by navigating to <code>localhost:2922/junkurl</code>, - if the URL does not resolve, cannot be found, or otherwise generates an exception, I want to display a friendly rendered cshtml page.  </p>
  
  <p>What I have in my web.config: </p>
  
  <pre><code>&lt;customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Views/Shared/Error.cshtml"&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>This results in the default yellow error page.  But if I drop an <code>error.html</code> page in the root and use this: </p>
  
  <pre><code>&lt;customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/error.html"&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>It works.  The only problem is, I don't want to have to build up my entire Layout / LoginPartial / etc all over again with straight html - I want to render it using razor.  What is the typical approach around this?  I've done tons of searching on this so apologies if I missed the answer, I'm just completely at a loss.  </p>
  
  <p>I would rather do this from code if possible, but I from what I understand, code will only cover a certain level of exceptions... at a certain point it seems it has to be handled via config.  I just wish it was straightforward config!</p>