suneeth
suneeth

Reputation: 165

#if DEBUG returns true on production server

We have the following code on the Global.asax of an MVC web application

    protected void Application_BeginRequest()
    {
        #if DEBUG
        if (!string.IsNullOrEmpty(HttpContext.Current.Request["debug"]))
        {
            RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
        }                
        #endif
    }

the "compilation debug" atribute set as "false" in web.config of the production server. So the expected behavior is that the above code will never get executed . it works most of the time, but then all of a sudden the app is starting to execute this code. It will continue to do so Until I do an IIS reset. I can't seem to figure out why all of a sudden our website goes into the debug mode automatically. any Idea?

Upvotes: 3

Views: 1192

Answers (1)

DavidG
DavidG

Reputation: 118937

The #if DEBUG line is a compiler directive and can only be called if the DEBUG constant has been defined manually in the code or specified in the build (which is set up in your project properties.

The web.config compilation value of debug="true" is a completely different thing. To determine if that has been set, you can use this instead:

var compilation = (CompilationSection)ConfigurationManager
                      .GetSection("system.web/compilation");

if (compilation.Debug)
{
    //Debug is on!
}

Upvotes: 5

Related Questions