852 Chapter 17 • Troubleshooting 101: Diagnostics in IIS 7.0
Confi guring Custom Error Messages Using IIS Manager
Let’s fi rst take a look at viewing and updating the Custom Errors pages using IIS Manager.
After opening and connecting to an IIS 7 server, click the Error Pages icon in the IIS section
and then click Open Feature from the Actions pane (or simply double-click the Error Pages icon),
as shown in Figure 17.3. These are the default Error Pages defi ned for the entire Web server. Any
changes done at this level will impact the error pages settings for all the sites supported on that IIS 7
server, except where a site or application overrides those values.
There are a number of options available at this point from a Status Code perspective. You can add
a Status Code by clicking Add. . .in the Actions pane (see Figure 17.4).
The Add Custom Error Page dialog box will allow you to provide a Status Code (e.g., 404) or a
Substatus Code (e.g., 404.14). The Path Type fi eld allows you to defi ne the kind of action to take based
on the value in the path (see Figure 17.4). Table 17.1 provides details on the available path types.
Figure 17.2 IIS 7.0 Detailed HTTP Error Message
Troubleshooting 101: Diagnostics in IIS 7.0 • Chapter 17 853
Figure 17.3 The IIS Manager
Figure 17.4 The Add Custom Error Page
854 Chapter 17 • Troubleshooting 101: Diagnostics in IIS 7.0
Controlling the custom errors can be done at a variety of locations within IIS 7, and thus it’s
important to understand where these settings are actually being stored. For the entire Web server,
those changes are done in the applicationHost.confi g fi le, which is located in the \Windows
\System32\Inetsrv\Confi g folder. Additionally, when you’re managing a given Web site, those changes
can also be stored in the applicationHost.confi g fi le, or they can be managed within the web.confi g
for the site.
HTTP error responses can be defi ned for the following IIS levels:
■
Web server
■
Web site
■
Web application
■
Physical directory
■
Virtual directory
■
File (URL)
These settings were previously available in IIS 6.0 but were not widely known and utilized. In
IIS 6.0, this was done by setting a number of properties (HTTPErrorCode, HTTPErrorSubcode,
URL, HandlerURL, FILE, or Filename) and using the proper combination, depending on the type of
redirection you where going to use. With IIS 7.0, this is much easier to implement in the User
Interface and via XML confi guration.
<httpErrors> Confi guration
With the rich integration between ASP.NET and IIS 7.0, a developer or administrator can defi ne the
httpError confi guration at the server, Web site, or virtual directory level. This provides a greater
amount of control versus what was previously available in IIS. The default <httpErrors> section is
defi ned in the applicationHost.confi g fi le. (More information on the location and use of the
applicationHost.confi g fi le can be found in Chapter 15).
Table 17.1 Available Path Types
Path Type Description Path Examples
File Points to a static fi le 404.htm
Execute URL Points to a dynamic fi le Error.aspx
Redirect Redirects the client browser to a different URL http://<URL>
Troubleshooting 101: Diagnostics in IIS 7.0 • Chapter 17 855
<httpErrors>
<error statusCode=“401” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“401.htm” />
<error statusCode=“403” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“403.htm” />
<error statusCode=“404” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“404.htm” />
<error statusCode=“405” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“405.htm” />
<error statusCode=“406” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“406.htm” />
<error statusCode=“412” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“412.htm” />
<error statusCode=“500” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“500.htm” />
<error statusCode=“501” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“501.htm” />
<error statusCode=“502” prefi xLanguageFilePath=“%SystemDrive%\inetpub\custerr”
path=“502.htm” />
</httpErrors>
The default location for the custom error pages is %SystemDrive%\inetpub\custerr. Within that
folder will be additional folders that map to a localized code. For U.S. English, that subfolder is
labeled “en-US.” The localized version that will be used for the response will be defi ned by the actual
browser setting that is set by the end user.
Table 17.2 Child <error> Node Attributes and Values
Attribute Name Value
defaultPath Default path to the HTTP error fi le or URL that will be
used within the child <error> node.
detailedMoreInformationLink At the bottom of a Detailed error page, a “More
Information” link redirects the user to a Microsoft
Support article. Setting the
DetailedMoreInformationLink property can override
the base URL for this link. This can be extremely
useful if you want to capture these errors, even for
internal testing, to store in a database or provide a
response using an internal Knowledge Base article
that directly references a particular product or
module (Default=“
?LinkID=62293”).
defaultResponseMode Used to defi ne the default Response Mode that will
be used within the child <error> node (Default=File):
File Static fi le will be used.
Continued
856 Chapter 17 • Troubleshooting 101: Diagnostics in IIS 7.0
Table 17.2 Continued
Attribute Name Value
ExecuteURL Points to a URL within the same server.
For this to work, it must be a URL that points to a
dynamic page (e.g., ASPX page) that resides within
the same application pool that generated the error.
Needless to say, you might not want to set this at the
server level if you host a number of sites with more
than one application pool. By default, you will receive
an error if you attempt to do this to a location
outside the appPool. However, you can actually get
around this and allow it to happen with an
appropriate registry key. Read the “Some
Independent Advice” sidebar for more details.
Redirect Redirects to a specifi c URL. The URL can be
on the same server or a completely different server
or site.
errorMode Defi nes whether a Custom Error page or Detailed
Error page is used upon a given error being
generated (Default=DetailedLocalOnly).
DetailedLocalOnly A detailed error will only be
displayed when the request comes from the local
machine.
Custom Custom pages will be used upon an error.
Detailed A detailed error response will be provided
regardless of a custom page being assigned
or outside the local machine.
existingResponse ASP.NET and IIS 7 are not integrated when it comes to
error responses. Thus this value allows you to control
the way you want to handle error responses
(Default=Auto):
Auto IIS 7.0 will go through a series of checks to
decide which error response will be used:
1. If the IHttpResponse::SetStatus method was called
with the fTrySkipCustomErrors fl ag, the existing
response is passed through, and no detailed or
custom error is shown.
2. If the ErrorMode property is set to Custom, the
response is replaced.
3. If ErrorMode is set to Detailed and there is an
existing response, the response is passed through.
4. If ErrorMode is set to Detailed and there is no
existing response, the response is replaced with a
detailed error message.