Search code examples
iis-7.5http-error

Specify default error page via web.config


How does one specify a single page as a fallback if specific error codes are not matched?

I have the following that matches a HTTP 500 and 404 error ..

<system.webServer>
  <httpErrors errorMode="Custom" defaultResponseMode="File">
    <clear />
    <error statusCode="500" path="my500errorHandler.html"/>
    <error statusCode="404" path="my404errorHandler.html"/>
  </httpErrors>
</system.webServer>

How do I define a default page to handle a HTTP error not specifically defined such as the 500 and 404 error are in the web.config?


Solution

  • Try following solution with Asp.Net.

    <configuration>
      <system.web>
        <customErrors defaultRedirect=”http://example.com/errors/Error.aspx” mode=”RemoteOnly”>
           <error redirect=”http://example.com/errors/404.aspx” statusCode=”404″ />
        </customErrors>
      </system.web>
    </configuration>
    

    Other generic solution for IIS here. Note that here: If you are using static html defaultResponseMode=File. If you are using dynamic page, you need to set efaultResponseMode="ExecuteURL"

    <configuration>
       <system.webServer>
          <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" 
      defaultPath="http://example.com/errors/Error.html">
             <remove statusCode="500" />
             <error statusCode="500"
                path="http://example.com/errors/500.html" />
           </httpErrors>
       </system.webServer>
    </configuration>