Custom Error Handling with ASP.NET
| Pathik H Rawal | |
| Intermediate | |
| Language: | C#, VB.NET |
| Platform: | Web |
<customErrors>
<customErrorsdefaultRedirect="url" mode="On|Off|RemoteOnly">
<error statusCode="statuscode" redirect="url"/>
</customErrors>
Required Attribute
|
Attribute |
Option |
Description |
|
Mode |
|
|
|
|
On |
Specifies that custom errors are enabled. If no defaultRedirect is specified, users see a generic error. |
|
|
Off |
Specifies that custom errors are disabled. This allows display of detailed errors. |
|
|
RemoteOnly |
Specifies that custom errors are shown only to remote clients and ASP.NET errors are shown to the local host. This is the default. |
Optional Attribute
|
Attribute |
Description |
|
defaultRedirect |
Specifies the default URL to direct a browser to if an error occurs. When defaultRedirect is not specified, a generic error is displayed instead. The URL may be absolute (for instance, http://www.dnzone.com/ErrorPage.htm) or it may be relative. A relative URL such as /ErrorPage.htm is relative to the Web.config file that specified the defaultRedirect URL, not to the Web page in which the error occurred. |
Example
The following example specifies the error handling pages to use for an ASP.NET application.
<configuration>
<system.web>
<customErrors defaultRedirect="Error.htm"
mode="RemoteOnly">
<error statusCode="500"
redirect="Error500.htm"/>
</customErrors>
</system.web>
</configuration>





