How do I configure web.config to show descriptive errors?

  • Page Owner: Not Set
  • Last Reviewed: 2018-09-04

How can I add more descriptive errors in a .net web project?


Answer

There are a few changes to make to your Web.config:

Under the <system.web> node, find or add the customErrors node and set the mode to Off or RemoteOnly:

 <customErrors mode="Off" />
  • Off will show all errors to everyone.
  • RemoteOnly will show errors only to users on localhost.

Under the <system.webServer> node, find or add the httpErrors node, set the errorMode attribute to Detailed or DetailedLocalOnly.

  • Detailed will show all errors to everyone.
  • DetailedLocalOnly will show errors only to users on localhost.

It can be helpful to set the compilation to debug mode, as this will provide better detail in errors:

<compilation debug="true" optimizeCompilations="false" />

If you're using a config transform, the following could work:

<system.web>
  <compilation debug="true" xdt:Transform="SetAttributes(debug)" />
  <customErrors mode="Off" xdt:Transform="Replace" />
</system.web>
<system.webServer>
  <httpErrors errorMode="Detailed" xdt:Transform="Replace"></httpErrors>
</system.webServer>