How do I enable .NET to show more detailed error messages?
By default, our Windows hosting servers display a generic error when any .NET application generates an exception. The error message resembles the following:
Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, set "mode" to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="On"default Redirect="mycustompage.htm"/>
</system.web>
</configuration>
We have set the default behavior for the hosting server this way for security reasons. When displaying a custom error message, it is possible for a malicious user to obtain sensitive information from the message. This is why we recommend you use this feature sparingly and only when troubleshooting. Additionally, be sure to re-enable the generic error message once you are finished debugging any problem.
To view the detailed error messages remotely, modify the following tag in the web.config file in the root of your application folder. If the tag does not exist, you can add it within the <configuration> and <system.web> tags:
To specify a custom error page to display, instead of the more detailed error message, add the following tag:
where MyErrorPage.aspx is the name of your error page.
Mode Values:
There are several possible Mode values.
- RemoteOnly:
- Only users logged on to the console of the server can view the detailed error messages. Remote users will see the generic error page unless the defaultRedirect is defined, in which case the custom page is displayed.
- On:
- No detailed error messages are shown. The custom error page will be used if it was specified in the defaultRedirect.
- Off:
- Detailed error messages are shown for remote and local users. Use this value to set the value of mode.
The defaultRedirect value is used to specify the error page to use when a .NET error is encountered. This URL is relative to the location of your web.config file, or if a tilde is used, is relative to the root of your application (for example: ~/MyErrorPage.aspx).