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 p开发者_Go百科reprocessor directives in aspx pages? Is there an alternative way to achieve my goal?
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
精彩评论