Partager via


Edit a Custom HTTP Error Response (IIS 7)

Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista

If you change the location of a custom error file, you can change the settings for the custom error to point to the new location. This is also useful if the file type for the error message changes, for example, from a static file to a file that serves dynamic content that is customized for each visitor.

Note

Editing a configuration setting changes the setting at the local level and for any child levels that inherit the setting.

Prerequisites

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

  • None

To edit a custom error

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.

User Interface

To Use the UI

  1. 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).

  2. In Features View, double-click Error Pages.

  3. On the Error Pages page, click to select the error you want to change.

  4. In the Actions pane, click Edit.

  5. In the Edit Custom Error Page dialog box, select one of the following:

    • Insert content from static file into the error response if your error content is static, such as an .html file.

    • Execute a URL on this site if your error content is dynamic, such as an .asp file.

    • Respond with a 302 redirect if you are redirecting a client browser to a different URL.

  6. In the File path text box, type the path of the custom error page if Insert content from static file into the error response is the chosen path type. If using either the Execute a URL on this site or Respond with a 302 redirect path type, type, instead, the URL of the custom error page. Click OK.

Command-line

Change the path type for a custom error

To change the path type for a custom error, use the following syntax:

appcmd set config /section:httpErrors /[statusCode='int'].responseMode: File|ExecuteURL|Redirect

The variable int is the HTTP status code of the custom error you want to change. For example, to change the path type for 404 errors that are returned by the server from File to Redirect, type the following at the command prompt, and then press Enter:

appcmd set config /section:httpErrors /[statusCode='404'].responseMode:Redirect

Change the path for a custom error

To change the path for a custom error, use the following syntax:

appcmd set config /section:httpErrors /[statusCode='int'].path: string

The variable int is the HTTP status code of the custom error you want to change, and the variable string is the new path of the custom error file.

For more information about Appcmd.exe, see Appcmd.exe (IIS 7).

Configuration

The procedure in this topic affects the following configuration elements:

  • <httpErrors>

For more information about IIS 7 configuration, see IIS 7.0: IIS Settings Schema on MSDN.

WMI

Use the following WMI classes, methods, or properties to perform this procedure:

  • HttpErrorsSection class (IIS)

  • CustomErrorsSection class (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.

See Also

Concepts

Configuring HTTP Error Responses in IIS 7