You will find loads of articles around the web reminding us all that running your production ASP.NET website in complication debug=true mode is a BAD THING!
- Don't run production ASP.NET Applications with debug="true" enabled
- Beware Of Deploying Debug Code In Production
- Top 10 Best Practices for Production ASP.NET Applications
To make sure we avoid this problem we have added a start up check in our application that will make sure that the build mode (debug or release) of our binaries match that of the web.config. As all releases are done via our build server all our binaries will be in release mode. However we tend to make major changes to the web.config on the live servers so deploying the web.config is usually not an option.
To check if the web.config has debug enabled you can use HttpContext.Current.IsDebuggingEnabled.
To check what mode a binary is in, we use the #DEBUG Preprocessor Directive: