views:

167

answers:

1

I am using MinifyJS.tt which is a T4 template to minify all my JS files automatically. In my aspx files, I am referencing all the javascript files.

Now, I want to add a condition (maybe compiler directive) to use the original JS file when I am debugging the application, and to use the minified JS files when I simply run the application without debug. I tried using #if in the aspx page, but that did not seem to work.

Can we make use of preprocessor directives in aspx pages? Is there an alternative way to achieve my goal?

+1  A: 

You can use the following:

if (!HttpContext.Current.IsDebuggingEnabled)
    Script = OptimizeScript(Script);

Further.....there are a couple of comments than discuss the topic further.

From Wilco Bauwer he comments that this property encapsulates the web.config setting and doesn't take the page level debugging into account and if you wanted to....

bool isDebuggingEnabled = Assembly.GetExecutingAssembly().IsDefined(typeof(DebuggableAttribute));

....this is the kiddy to achieve it!!

and Peter Bromberg (C# MVP) offers up another solution using the Global.asax.cs file and a static global application flag being set in the Application_Start event.

public static bool IsDebugMode = false;
protected void Application_Start(object sender, EventArgs e)
{
   if (System.Diagnostics.Debugger.IsAttached) IsDebugMode = true;

Taken from Steves blog

Bipul
I used the last approach of Peter Bromberg and added it to the AuthenticateRequest method. This helps when you Attach debugger when the application is running.Thanks
Zuber
Good to know it helped you :)
Bipul