Web.Config customErrors use profile element

In Web.Config configuration file, customErrors element provides information about the ASP.NET application custom error messages.

Look at the example of the configuration structure:

<the Configuration>
   <system.web>
      <customErrors>
   <customErrors defaultRedirect = "url" the MODE = "the On | Off | RemoteOnly">
   <error statusCode = "StatusCode" redirect = "url" />
</ customErrors>
Required Properties
Properties option description
    Mode Specifies to enable, disable, or only a remote client displays a custom error.
    On Specifies to enable custom error. If no defaultRedirect, the user will see a generic error.
    Off Specifies to disable custom error. This allows you to display detailed error.
    RemoteOnly specify only end to end display a custom error to remote clients, and ASP.NET errors display the local host. It's the default value.

Optional attributes
Attribute Description
defaultRedirect specify default browser when an error occurs URL points to. If no defaultRedirect, a generic error is displayed. URL can be either absolute (eg http: //www.***.com/ErrorPage.htm), also it can be relative. Relative URL (such as /ErrorPage.htm) is relative to the specified terms defaultRedirect Web.config file, rather than an error page. Tilde (~) at the beginning of the URL (such as ~ / ErrorPage.htm) is represented by the URL specified in the application with respect to the root path terms.

Subtag
sub-described tag
<error> sub-tag error can occur multiple times. Each occurrence will define a custom error condition.

Notes
<customErrors> element does not apply to errors in the XML Web service.

Example
The following example specifies the error pages ASP.NET application.

<configuration>
   <system.web>
      <customErrors defaultRedirect="GenericError.htm"
                    mode="RemoteOnly">
         <error statusCode="500"
                redirect="InternalError.htm"/>
      </customErrors>
   </system.web>
</configuration>
要求
包含在:<system.web> 中
Web 平台:IIS 5.0、IIS 5.1、IIS 6.0
配置文件:Machine.config、Web.config

Guess you like

Origin www.cnblogs.com/itjeff/p/11911749.html