title: IIS7 web server custom errors - works on local but not when published to production
body: <p>I am building a new site with custom error pages.  I have setup my web.config, and have all of my pages setup.</p>
  
  <p>When I run locally, and force errors (page not found is the easy one), it all works well.  But when I publish to my Windows Server 2008 R2 production server, and enter a bad page, it still takes me to the default IIS7 error page.</p>
  
  <p>Here is a sample from my web.config (and my pages are all there):</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0"/&gt;
      &lt;customErrors mode="On" defaultRedirect="~/ErrorGeneral"&gt;
        &lt;error statusCode="400" redirect="~/ErrorBadRequest" /&gt;
        &lt;error statusCode="401" redirect="~/ErrorUnathorized" /&gt;
        &lt;error statusCode="402" redirect="~/ErrorPaymentRequired" /&gt;
        &lt;error statusCode="403" redirect="~/ErrorForbidden" /&gt;
        &lt;error statusCode="404" redirect="~/ErrorItemNotFound" /&gt;
        &lt;error statusCode="405" redirect="~/ErrorMethodNotAllowed" /&gt;
        &lt;error statusCode="406" redirect="~/ErrorNotAcceptable" /&gt;
        &lt;error statusCode="412" redirect="~/ErrorPreconditionFailed" /&gt;
        &lt;error statusCode="500" redirect="~/ErrorInternalServerError" /&gt;
        &lt;error statusCode="501" redirect="~/ErrorNotImplemented" /&gt;
        &lt;error statusCode="502" redirect="~/ErrorBadGateway" /&gt;
      &lt;/customErrors&gt;
      &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Am I doing something simple incorrectly?  Is it a difference with Windows Server 2008 R2?</p>
  
  <p>EDIT:  I found the issue, which is additional information in the web.config file, to look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;customErrors mode="On" defaultRedirect="~/ErrorGeneral"&gt;
        &lt;error statusCode="400" redirect="~/ErrorBadRequest" /&gt;
        &lt;error statusCode="401" redirect="~/ErrorUnathorized" /&gt;
        &lt;error statusCode="402" redirect="~/ErrorPaymentRequired" /&gt;
        &lt;error statusCode="403" redirect="~/ErrorForbidden" /&gt;
        &lt;error statusCode="404" redirect="~/ErrorItemNotFound" /&gt;
        &lt;error statusCode="405" redirect="~/ErrorMethodNotAllowed" /&gt;
        &lt;error statusCode="406" redirect="~/ErrorNotAcceptable" /&gt;
        &lt;error statusCode="412" redirect="~/ErrorPreconditionFailed" /&gt;
        &lt;error statusCode="500" redirect="~/ErrorInternalServerError" /&gt;
        &lt;error statusCode="501" redirect="~/ErrorNotImplemented" /&gt;
        &lt;error statusCode="502" redirect="~/ErrorBadGateway" /&gt;
      &lt;/customErrors&gt;
      &lt;/system.web&gt;
      &lt;system.webServer&gt;
          &lt;httpErrors&gt;
              &lt;remove statusCode="502" subStatusCode="-1" /&gt;
              &lt;remove statusCode="501" subStatusCode="-1" /&gt;
              &lt;remove statusCode="500" subStatusCode="-1" /&gt;
              &lt;remove statusCode="412" subStatusCode="-1" /&gt;
              &lt;remove statusCode="406" subStatusCode="-1" /&gt;
              &lt;remove statusCode="405" subStatusCode="-1" /&gt;
              &lt;remove statusCode="403" subStatusCode="-1" /&gt;
              &lt;remove statusCode="401" subStatusCode="-1" /&gt;
              &lt;remove statusCode="404" subStatusCode="-1" /&gt;
              &lt;error statusCode="404" prefixLanguageFilePath="" path="/Pages/ErrorItemNotFound.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="401" prefixLanguageFilePath="" path="/Pages/ErrorUnauthorized.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="403" prefixLanguageFilePath="" path="/Pages/ErrorForbidden.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="405" prefixLanguageFilePath="" path="/Pages/ErrorMethodNotAllowed.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="406" prefixLanguageFilePath="" path="/Pages/ErrorNotAcceptable.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="412" prefixLanguageFilePath="" path="/Pages/ErrorPreconditionFailed.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="500" prefixLanguageFilePath="" path="/Pages/ErrorInternalServerError.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="501" prefixLanguageFilePath="" path="/Pages/ErrorNotImplemented.aspx" responseMode="ExecuteURL" /&gt;
              &lt;error statusCode="502" prefixLanguageFilePath="" path="/Pages/ErrorBadGateway.aspx" responseMode="ExecuteURL" /&gt;
          &lt;/httpErrors&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>