Specify default error page via web.config

How do I specify a single page as a fallback if specific error codes do not match?

I have the following which matches HTTP error 500 and 404.

<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 an HTTP error not specifically defined, such as 500 and 404 errors in web.config?

+3


source to share


1 answer


Try the 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>

      



Another general solution for IIS is here . Please note here: If you are using static html defaultResponseMode = File. If you are using a 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>

      

+2


source







All Articles