Name
<error>
Synopsis
<error statusCode=httpStatusCode redirect=Url />
Specifies a custom error page to handle redirections for a specific HTTP status code.
Scope
Any
Attributes
-
statusCode Specifies the HTTP status code (such as 404 for a “Not Found” error) for the specified custom error page. This attribute is optional.
-
redirect Specifies the URL of the page to which requests with a matching HTTP status code should be redirected. This attribute is optional.
Child Elements
None
Example
The example configures a custom error page for 404 errors, and the default error page configured in the previous example:
<configuration>
<system.web>
<customErrors
defaultRedirect="Error.aspx">
<error statusCode="404" redirect="My404ErrorPage.aspx"/>
</customErrors>
</system.web>
</configuration>Notes
While custom error pages provide a convenient way to prevent users from seeing raw error messages (and perhaps provide more helpful messages), they are not a substitute for proper exception handling. By the time an error reaches a custom error page, recovering from the error gracefully will be much more difficult, which can degrade the experience of your users.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access