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

asp.net, asp.net-mvc, web-config

Solution

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.

Problem

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

Original source

Related problems