html - @{#if DEBUG} 不起作用

标签 html asp.net-mvc-3 web-config minify

我的 web.config 文件包含这个

<compilation debug="false" targetFramework="4.0">
   <assemblies>
      // some assemblies
   </assemblies>
</compilation>

在我的 _Layout.cshtml 文件中我有

@{#if DEBUG}
  // include all css and js files
@{#else}
  // include the minified and combined versions of the css and js files
@{#endif} 

问题是 @{#if DEBUG} 分支被执行。如果我将该分支更改为 @{#if !DEBUG},则 else 分支将被执行。这是为什么?

谢谢。

萨钦

最佳答案

Web.config debug="" 属性不会影响预处理器符号。

您可以像这样直接检查该属性:

var compilation = WebConfigurationManager.GetSection("system.web/compilation") as CompilationSection;
return compilation != null && compilation.Debug;

(您应该将其放入任何类的静态属性中,然后在正常的 if 语句中检查该属性)

关于html - @{#if DEBUG} 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9520976/

相关文章:

iis - 在 IIS7 中重写 URL

html - 谁能告诉我为什么当我更改填充而不是其他时此列表会消失?

c# - Ninject 的 .NET MVC3 服务定位器/依赖解析器问题

c# - "When the site administrator has locked access to this section using <location allowOverride="假 "> from an inherited configuration file."

c# - 将参数传递给 Controller ​​ ..但不在 URL 上

asp.net-mvc-3 - @Html.BeginForm 在页面上显示 "System.Web.Mvc.Html.MvcForm"

c# - 获取当前应用配置文件的文件路径

html - 如何在我的移动网站上创建一个链接以使 Blackberry 调用电话?

javascript - 当表单项未回复时如何发出警报?

html - 自定义 HTML 高级格式 : Assistance