Custom Error mode in Web.Config file - C# ASP.Net


CustomError mode in web.config file and Use

CustomErrors Element : "Provides information about custom error messages for an ASP.NET application. The customErrors element can be defined at any level in the application file hierarchy".

The ASP.NET framework provides built-in settings to control how to respond when an application error occurs. This functionality is part of the Web.Config customErrors section.

Configuration Options for Web.Config <customErrors>

Like most web.config settings, customErrors can be configured within the Machine.config, root web.config or your application web.config file. Usually, it is set per application.

CustomErrors supports the following modes: The Error mode attribute determines whether or not an ASP.NET error message is displayed. By default, the mode value is set to "RemoteOnly".

1) Off Mode : When the error attribute is set to "Off", ASP.NET uses its default error page for both local and remote users in case of an error.

2) On Mode : In case of "On" Mode, ASP.NET uses user-defined custom error page instead of its default error page for both local and remote users. If a custom error page is not specified, ASP.NET shows the error page describing how to enable remote viewing of errors.

3) RemoteOnly : ASP.NET error page is shown only to local users. Remote requests will first check the configuration settings for the custom error page or finally show an IIS error.


<configuration>
  <system.web>
    <customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly">
      <error statusCode="500" redirect="ErrorPage.aspx"/>

      <error statusCode="403" redirect="ErrorPage.aspx" />     
      <error statusCode="404" redirect="ErrorPage.aspx" />
    </customErrors>
  </system.web>
</configuration>



Disabling Custom Errors: 

 To do this, you will want to set customErrors mode to “Off” as shown below. Be careful though as this could expose sensitive information shown in error messages as well as detailed stack traces.

 

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

 

More:  Custom Error mode in Web.Config file - C# ASP.Net

 

Post a Comment

If you have any questions or concerns, please let me know.

Previous Post Next Post