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.
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.