Custom Error in web.config


Hello guys as we know we face the problem sometimes page not found (404) and if any error occurred (page level or database connection). Users get confused what is happening if something goes wrong around application. For that we can use Custom Error mode in web.config setting. Here is the code, write below code in :

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPage.aspx">
      <error statusCode="404" redirect="~/ ErrorPage.aspx"/>
     
      <error statusCode="404" redirect="~/ ErrorPage.aspx"/>
     
    customErrors>

Here are few details regarding above:

There are Custom error modes which are:
  • Off - Everyone gets to see your errors (either on server or local)
  • On - Everyone gets the error page (created by you) either on server or local.
  • RemoteOnly - only the local can see the error exactly but server still see the page created by you
DefaultRedirect: If any error occurred in your website, it redirect to your custom error page.
statusCode(404) : It redirects to the custom error page when page not found on your server.
statusCode(405) : It redirect to the custom error page when any forbidden error occurred in your page.

Comments