Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Tuesday, May 05, 2009

Making sure your application is not left in debug="true"

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!
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:

   1: // codesnippet:ADB0358E-3BD1-11DE-B2D2-764056D89593
   2: public static BuildModeEnum BuildMode
   3: {    
   4:     get    
   5:     {        
   6:         #if (DEBUG)
   7:             return BuildModeEnum.Debug;
   8:         #else
   9:             return BuildModeEnum.Release;
  10:         #endif
  11:     }
  12: }




Labels: , , ,

0 Comments:

Post a Comment

<< Home