Exclusively for you!! Trial version of Google Apps, Apply Coupon-CNHPGX6T6QRWGV!!

Custom error mode in ASP.NET web.config

Resolved-error @Image courtesy of Stuart Miles/ FreeDigitalPhotos.net

Custom error mode in ASP.NET web.config

Welcome to CodeSpread!

Dual Roles

As a developer, I would love to see the error page that provides details of the error, status code and also the stack information. This information is useful to debug the application but soon becomes an ugly yellow page when I switched my role from developer to user.

Who wants to see an ugly yellow page? Just a developer (sigh!)

Here comes the custom error page to the rescue, from yellow page,to indicate an error. We just have to bring some configuration changes in the ><customErrors> section of our web.config file.

How we add custom error configuration?

Custom 404 and 500 errors are typically used to redirect the user to the error page.

Let’s see an example,

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />

We can see that the mode selected is RemoteOnly. we have, in all 3 modes:

1) Off Mode: It signifies that custom errors are disabled. In this mode, the same ugly error page is shown which we, as a developer, consider helpful for debugging purpose.
2) On Mode: It signifies custom errors are enabled, and as discussed above, user is redirected to a custom error page. In the above example, user may be redirected to NoAcess.htm or FileNotFound.htm on specific errors.
3) RemoteOnly Mode: Same as ON Mode, custom errors are enabled. The difference lies in the request originating from, like if the request originates from a remote machine page is redirected to custom error page else if the request originates from the local machine the default error page is shown.

Selecting a mode is a mandatory action.The default mode is RemoteOnly.

We have “defaultRedirect” element which is optional and as the name suggests, user is redirected to a default URL.

Two lines of configuration and relaxed eyes of user enhances user’s experience.

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On


  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

More from CodeSpread:

  • Split the Web.ConfigSplit the Web.ConfigWhen we work on web projects, we usually encounter with web.config files, not one but may be many at the same time. These web.config files are ASP.NET configuration files. They can be distributed t...
  • Error Handling at Page level or Application levelError Handling at Page level or Application levelA regular query of a developer as which is the best way to handle errors? at Page level or Application level. Best answer is why to chose one over the other? Lets have both. We will try some sam...
  • When ViewState is loaded?When ViewState is loaded?We know asp.net page life cycle and on subsequent request, each stage of life cycle is analyzed to find out, as and when viewstate is available for use.
  • Maintain Page State on Browser’s Back Button ClickMaintain Page State on Browser’s Back Button ClickThis is a very common requirement and a major expectation for a quality user experience. Scenario: User visits a site which heavily uses AJAX. Here, AJAX will not let the user navigate from the p...
  • Don’t Mess with App_OfflineDon’t Mess with App_OfflineOne of the most useful features of ASP.NET is the "App_Offline.htm" . It provides a much easy way to make the ASP.NET application offline while we do our modifications on the site. How we do it? ...
  • Caching is an evilCaching is an evilI know 'Caching' was created to ease out the network resources but i have seen the situations where it emerged as the biggest evil. I can remember many situations when the website is updated but...
  • How to create a MVC 2 Project in VS2010?How to create a MVC 2 Project in VS2010?How to create a MVC 2 Project in VS2010? 1. Open VS2010. 2. Select File -> New Project. 3. Select Visual C# -> Web -> ASP.NET MVC 2 Empty Web Application. Name it as MyMvcApplicat...
  • Asp.Net: Hidden Truth of CookiesAsp.Net: Hidden Truth of CookiesI know there are several articles on cookies as what are they? and how can they be created? but i always wanted to know more about them. My questions were where they are stored? how to track their ...