【问题标题】:Unable to generate 'VersionQueryString' in Scripts.Render when using bundle使用捆绑包时无法在 Scripts.Render 中生成“VersionQueryString”
【发布时间】:2014-09-29 13:45:33
【问题描述】:

这是我的设置:

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/" + Links.Scripts.jquery_2_1_1_min_js,
                    "~/" + Links.Scripts.jquery_migrate_1_2_1_min_js,
                    "~/" + Links.Scripts.calendar.jquery_ui_datepicker_cc_all_min_js
                    ));
    }
    protected void Application_Start()
    {
        RegisterBundles(BundleTable.Bundles);
        BundleTable.EnableOptimizations = true;
    }

在布局视图中使用此代码:

@Scripts.Render("~/bundles/jquery")

在VS没问题。 但是当发布我的项目并将其部署在 IIS8.0 中时无法生成 VersionQueryString,这是 HTML 输出:

<script src="/Test/bundles/jquery?v="></script>

但这是个问题。Html 输出必须是这样的:

<script src="/Test/bundles/jquery?v=D8YBlpJkSh-c2SxXkODfl3ftU01p3BTOtqGF3Uuuq9E1"></script>

什么原因会导致无法生成VersionQueryString?

【问题讨论】:

  • 你试试@Scripts.Render("~/bundles/jquery?v=")
  • 否。这是一个 Html 输出。Html 输出必须是这样的:

标签: c# asp.net-mvc bundle bundling-and-minification


【解决方案1】:

更改此行

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/" + Links.Scripts.jquery_2_1_1_min_js,
                "~/" + Links.Scripts.jquery_migrate_1_2_1_min_js,
                "~/" + Links.Scripts.calendar.jquery_ui_datepicker_cc_all_min_js
                ));
}

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                VirtualPathUtility.ToAppRelative(Links.Scripts.jquery_2_1_1_min_js),
                VirtualPathUtility.ToAppRelative(Links.Scripts.jquery_migrate_1_2_1_min_js),
                VirtualPathUtility.ToAppRelative(Links.Scripts.calendar.jquery_ui_datepicker_cc_all_min_js)
                ));
}

VirtualPathUtility.ToAppRelative: 使用 System.Web.HttpRuntime.AppDomainAppVirtualPath 属性中的应用程序虚拟路径将虚拟路径转换为应用程序相对路径。

【讨论】:

  • 和OP有什么区别?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 2023-03-23
  • 2014-12-23
相关资源
最近更新 更多