Customizing Error Pages
Depending on the circumstances, you might want to handle application
errors in different ways. For example, at development time you
probably want to see the detailed error pages that ASP.NET provides
to help you identify and fix problems. However, once an
application is being served in a production environment, you probably
do not want to display detailed errors to your customer clients.
You can use ASP.NET to specify whether errors are shown
to local clients, to remote clients, or to both. By default,
errors are shown only to local clients (those clients on the same
computer as the server). You can also specify a custom error page
to redirect clients to if an error occurs.
Custom errors are enabled in the Web.config file for an application. For example:
<configuration>
<system.web>
<customErrors defaultRedirect="genericerror.htm" mode="remoteonly" />
</system.web>
</configuration>
This configuration enables local clients to see the default ASP.NET
detailed error pages but redirects remote clients to a custom page, genericerror.htm.
This page could be an .aspx page as well. ASP.NET passes the path of the page
on which the error occurred to the error page as a
QueryString argument. Note that if the execution of the
error page generates an error, a blank page is sent back to the
remote client.
<%@ Page Language="VB" Description="Error page"%>
<html>
<head>
<title>Error page</title>
</head>
<body>
<h1>Error page</h1>
Error originated on: <%=Request.QueryString("ErrorPage") %>
</body>
</html>
VB
Note: Only files mapped to the aspnet_isapi.dll extension in IIS
generate these errors. Files not served through the aspnet_isapi.dll are
not processed by ASP.NET and generate IIS errors. See the IIS
documentation for information about configuring IIS custom errors.
The following table describes the configuration attributes and
values for the <customerrors> tag.