Custom error pages in ASP.NET MVC

I had a bit of troubles getting custom error pages working with ASP.NET MVC. The solution I ended up with was using httpErrors-element in Web.config.

While that made everything work – it also masked error messages when developing locally. Now the httpErrors section has a errorMode="DetailedLocalOnly" attribute-value but it did not work satisfactory to me (still showing IIS 7.0 error pages). I resorted to adding the httpErrors section in the config transform files.

In my Web.Release.config:

<system.webServer>
  <httpErrors errorMode="Custom" existingResponse="Replace" xdt:Transform="Insert">
    <remove statusCode="404" subStatusCode="-1" />
    <remove statusCode="500" subStatusCode="-1" />
    <error statusCode="404" path="/Error/NotFound" responseMode="ExecuteURL" />
    <error statusCode="500" path="/Error/ServerError" responseMode="ExecuteURL" />
  </httpErrors>
</system.webServer>
The customErrors attribute is set to RemoteOnly.
<customErrors mode="RemoteOnly"></customErrors>

published in ASP.NET MVC