Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom error page in "Release" mode and default error page in "Debug" mode

I want to show a custom error page when the project is in production (release mode) and show the default error page from asp.net when running the page in (debug mode).

I have three Web.config files in my project.

  • Web.config
  • Web.Debug.config
  • Web.Release.config

This is what I have tried but had no luck.

Web.config

<customErrors mode="On" defaultRedirect="~/Home/Error">
    <error statusCode="404" redirect="~/Home/Error" />
</customErrors>

Web.Debug.config

<customErrors mode="Off" xdt:Transform="Replace"></customErrors>

Web.Release.config

<customErrors mode="On" defaultRedirect="~/Home/Error">
    <error statusCode="404" redirect="~/Home/Error" />
</customErrors>

Does anyone know how I can do this?

Thanks in advance :)

Edit: After reading around, I'm thinking that this is a known bug but I wasn't able to find a bug fix for this. If anyone knows more about this, please share. Thanks

like image 472
Farhan Ahmad Avatar asked Aug 27 '12 13:08

Farhan Ahmad


2 Answers

Okay. So I figured out what was wrong.

Web.config

<customErrors mode="Off" defaultRedirect="~/Error.htm"></customErrors>

Web.Debug.config

<compile debug="true" />
<customErrors mode="Off" xdt:Transform="Replace"></customErrors>

Web.Release.config

<customErrors mode="On" defaultRedirect="~/Error.htm" xdt:Transform="Replace">
     <error statusCode="404" redirect="~/Error.htm" />
</customErrors>

The changes above will keep error messages disabled by default and whenever the project is deployed on the production server, the settings in Web.Release.config will overwrite the default Web.config

Here is a list of resources / links that I found helpful:

  • Use Visual Studio web.config transform for debugging
  • http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx

I hope this helps anyone else that is trying to accomplish the same thing.

like image 163
Farhan Ahmad Avatar answered Oct 13 '22 00:10

Farhan Ahmad


This is a know bug. That feature can be used right now only as part of the deploy process. Please check this below post

How can I use Web.debug.config in the built-in visual studio debugger server?

or you could just use the 'default' web.config as your development/debugging version, and then the web.release.config would of course continue to be the release version, since its transforms are applied when you publish.

Hope it will help.

like image 40
Pankaj Agarwal Avatar answered Oct 13 '22 00:10

Pankaj Agarwal