使用捆绑包时,无法在Scripts.Render中生成“ VersionQueryString” [英] Unable to generate 'VersionQueryString' in Scripts.Render when using bundle

查看:72
本文介绍了使用捆绑包时,无法在Scripts.Render中生成“ VersionQueryString”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:

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;
    }

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

Use this code in Layout view:

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

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

In VS no problem. But when publish my project and deploy it in IIS8.0 unable to generate VersionQueryString,this is HTML output:

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

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

But this is a problem.Html Output must be something like this:

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

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

What reason will cause the unable to generate VersionQueryString?

推荐答案

更改此行

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属性中的应用程序虚拟路径到应用程序相对路径的虚拟路径。

VirtualPathUtility.ToAppRelative: Converts a virtual path to an application-relative path using the application virtual path that is in the System.Web.HttpRuntime.AppDomainAppVirtualPath property.

这篇关于使用捆绑包时,无法在Scripts.Render中生成“ VersionQueryString”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆