【问题标题】:ASP.NET web forms BundleTable is still bundling in debug modeASP.NET Web 表单 BundleTable 仍在调试模式下捆绑
【发布时间】:2012-09-19 10:29:32
【问题描述】:

我有一个 ASP.NET Web 表单应用程序,使用 Microsoft.AspNet.Web.Optimization 包中的新捆绑和缩小功能在 .NET 4.5 上运行。

到目前为止,这是一个非常简单的设置,只需一个捆绑包。

BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/send").Include(
        "~/scripts/GrowingInput.js", 
        "~/scripts/textboxlist/TextboxList.js",
        "~/scripts/textboxlist/TextboxList.Livesearch.js",
        "~/scripts/combobox/ui.combobox.js",
        "~/scripts/jquery-ui-timepicker.js",
        "~/scripts/msp.send.js"));
}

Global.asax

protected void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

发送.aspx

<%: Scripts.Render("/bundles/send") %>

这始终在 Web 浏览器中呈现为 &lt;script src="/bundles/send"&gt;&lt;/script&gt;,而忽略 web.config 中的 debug 设置为 true 还是 false。

我尝试将 BundleTable.EnableOptimizations = false; 添加到 BundleConfig.cs 以强制关闭捆绑,但这没有任何区别。

希望像在 MVC 网站中那样工作(Microsoft 文档似乎建议 Web 表单应该是相同的)。

  1. 使用调试标志打开/关闭捆绑
  2. 附加缓存清除 ?v=xxx 查询字符串以进行版本控制。

【问题讨论】:

    标签: asp.net asp.net-optimization bundling-and-minification


    【解决方案1】:

    Bundles路径必须以~开头,但是Scripts.Render方法不限于bundles,所以它只是将url视为本地资源,(它使用BundleTable.Bundles.GetBundleFor(path)来确定url是否为一个包)

    你只需要添加一个 ~ 这样就可以了:&lt;%: Scripts.Render("~/bundles/send") %&gt;

    【讨论】:

      猜你喜欢
      • 2013-05-25
      • 2013-01-30
      • 2012-11-30
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2018-02-01
      相关资源
      最近更新 更多