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.
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
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:
I hope this helps anyone else that is trying to accomplish the same thing.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With