Create a Custom HTTP Error Response (IIS 7)
Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista
IIS can return a custom error message whenever an HTTP error occurs. Custom error messages can provide friendlier or more informative feedback than default error messages.
|You cannot customize the following HTTP errors: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.|
|Adding a configuration setting adds the setting at the local level and to any child levels that inherit the setting.|
For information about the levels at which you can perform this procedure, and the modules, handlers, and permissions that are required to perform this procedure, see HTTP Error Responses Feature Requirements (IIS 7).
Exceptions to feature requirements
You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.
Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
In Features View, double-click Error Pages.
In the Actions pane, click Add.
In the Add Custom Error Page dialog box, under Status code, type the number of the HTTP status code for which you want to create a custom error message.
In the Response Action box:
Select Insert content from static file into the error response to serve static content, for example, an .html file, for the custom error.
Select Execute a URL on this site to serve dynamic content, for example, an .asp file for the custom error.
Select Respond with a 302 redirect to redirect client browsers to a different URL that contains the custom error file.
- Select Insert content from static file into the error response to serve static content, for example, an .html file, for the custom error.
In the File path text box, type the path of the custom error page if you chose Insert content from static file into the error response, or the URL of the custom error page if you use either the Execute a URL on this site or Respond with a 302 redirect path type, and then click OK.
Note If Execute a URL on this site is selected, the path must be a URL relative to the root of the current site. For example, if you want the URL "http://contoso.com/products/new/error.htm", then you should specify "/ products/new /error.htm". Note If Execute a URL on this site is selected, you must make sure that the specified URL is in the same application pool as the URL where the error might occur; otherwise, the server will return a 403 Forbidden message. If you cannot guarantee that the specified URL will be in the same application pool as all URLs where errors may occur, select Respond with a 302 redirect, instead, and specify a fully qualified URL.
To add a custom error, use the following syntax:
appcmd set config /section:httpErrors /+"[statusCode=' int ',subStatusCode=' int ', prefixLanguageFilePath=' string ',path=' string ',responseMode='File|ExecuteURL|Redirect']"
The variable statusCode int is the HTTP status code. The variable subStatusCode int is the HTTP sub status code. The variable prefixLanguageFilePath string is the path of the prefix language file. The variable path string is the path of the custom error file. For example, to add a custom error for any 401.2 errors returned from the server, type the following at the command prompt, and then press Enter:
appcmd set config /section:httpErrors /+"[statusCode='401',subStatusCode='2',prefixLanguageFilePath='%SystemDrive%\inetpub\custerr',path='401.htm',ResponseMode='File']"
For more information about Appcmd.exe, see Appcmd.exe (IIS 7).
The procedure in this topic affects the following configuration elements:
For more information about IIS 7 configuration, see IIS 7.0: IIS Settings Schema on MSDN.
Use the following WMI classes, methods, or properties to perform this procedure:
HttpErrorsSection.Add method (IIS)
CustomErrorsSection.Add method (ASP.NET)
For more information about WMI and IIS, see Windows Management Instrumentation (WMI) in IIS 7. For more information about the classes, methods, or properties associated with this procedure, see the IIS WMI Provider Reference on the MSDN site.