【发布时间】:2015-08-11 02:15:13
【问题描述】:
我正在尝试将捆绑包添加到现有的 ASP.NET Webforms 解决方案,但我的捆绑包总是呈现为空,我不确定为什么。我一直在关注this blog post。
到目前为止我有:
- 添加了 Microsoft ASP.NET Web 优化框架 NuGet 包
- 确保包含所需的参考资料
- 尝试在 Web.config 中使用 debug="false" 和 debug="true"
- 在我的解决方案中添加了以下代码
Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
App_Start/BundleConfig.cs
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/Global").Include(
"~/js/jquery-{version}.js",
"~/js/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/bundles/GlobalHead").Include(
"~/js/modernizr*"));
bundles.Add(new StyleBundle("~/Content/Global").Include(
"~/css/site.css"));
}
}
Site.Master
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundle/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundle/Global") %>
</body>
Web.Config
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
更新
需要明确的是,当我打开网页并使用 chrome 开发工具检查资源时,我可以看到
Content/Site.css
bundle/Global.js
bundle/GlobalHead.js
但是在检查它们时,它们没有内容。
【问题讨论】:
标签: c# asp.net webforms bundle