Trapping 404 and 500 errors in an MVC website web.config

There are two sections in the Web.config that need custom error handling settings.
How to redirect 404 and 500 errors with system.webServer httpErrors
In the system.webServer section, add an httpErrors node. First, remove the 404 and 500 statusCodes, then add them back, redirecting to custom message html files.
 
<system.webServer>
  <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
    <remove statusCode="404" />
    <remove statusCode="500" />
    <error statusCode="404" path="404.html" responseMode="File" />
    <error statusCode="500" path="500.html" responseMode="File" />
  </httpErrors>
 
How to use the system.web customErrors section to create redirects
In the system.web section, add a customErrors section, with a default custom error html file, a custom 404 file, and a custom 500 error html file.
 
<system.web>
  <customErrors mode="On" defaultRedirect="apperror.html" redirectMode="ResponseRedirect">
    <error statusCode="404" redirect="404.html" />
    <error statusCode="500" redirect="500.html" />
  </customErrors>
 
How to use the Debug and Release web.config Transforms to create rewite rules
Here's how to make these settings in the web.release transform file.
 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

    <customErrors mode="On" defaultRedirect="apperror.html" redirectMode="ResponseRedirect" xdt:Transform="Replace">
      <error statusCode="404" redirect="404.html" />
      <error statusCode="500" redirect="500.html" />
    </customErrors>
  </system.web>
  
  <system.webServer>
    <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace" xdt:Transform="Insert">
      <remove statusCode="404" />
      <remove statusCode="500" />
      <error statusCode="404" path="404.html" responseMode="File" />
      <error statusCode="500" path="500.html" responseMode="File" />
    </httpErrors>
  </system.webServer>
</configuration>