Somacon.com: Articles on websites & etc.

§ Home > Index > Web Development

customErrors and httpErrors not working in IIS 7.5 for 404, 500 error

This article provides a sample web.config file for ASP.Net applications running on IIS 7.5. It shows how to configure the customErrors and httpErrors sections for custom error messages on 404 and 500 server errors.

Getting customErrors and httpErrors to work in IIS 7.5 can be tricky. The below settings worked for me. They handle both errors from static pages and ASP.Net pages. Instead of showing the default error pages, the settings below cause IIS to display user-friendly, static HTML pages to the user. If your customErrors are not working, try the web.config settings below.

The 404 HTTP status code is for page not found error.

The 500 HTTP status code is for internal server errors.

Web.Config Sample Code

<?xml version="1.0"?>
<configuration>
  <system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="~/error/InternalServerError.htm">
      <error statusCode="404" redirect="~/error/PageNotFound.htm"/>
    </customErrors>
  </system.web>
  <system.webServer>
    <httpErrors errorMode="Custom" defaultResponseMode="File">
      <clear />
      <error statusCode="500" path="error\InternalServerError.htm"/>
      <error statusCode="404" path="error\PageNotFound.htm"/>
    </httpErrors>
  </system.webServer>
</configuration>

References


Have you heard of the new, free Automated Feeds offered by Google Merchant Center? Learn more in Aten Software's latest blog post comparing them to traditional data feed files.
Created 2012-06-09, Last Modified 2013-02-11, © Shailesh N. Humbad
Disclaimer: This content is provided as-is. The information may be incorrect.