C# 如何在.NET MVC(4.7.2)应用程序的ScriptBundle中包含SRI哈希?

C# 如何在.NET MVC(4.7.2)应用程序的ScriptBundle中包含SRI哈希?,c#,asp.net-mvc,asp.net-mvc-4,subresource-integrity,C#,Asp.net Mvc,Asp.net Mvc 4,Subresource Integrity,目前,我的捆绑包正在使用公共库的本地副本 bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", "~/Scripts/moment.min.js", "~/Scripts/boo

目前,我的捆绑包正在使用公共库的本地副本

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/moment.min.js",
                      "~/Scripts/bootstrap-datetimepicker.min.js",
                      "~/Scripts/respond.js"));
我希望转换为使用CDN,并希望通过包含哈希值来确保我与SRI保持一致。我找到了很多关于在bundle配置中使用CDN的文章,但是没有任何关于如何在绑定时包括SRI散列和crossorigin标记的文章

请帮助我。

试试这个:

 public static void RegisterBundles(BundleCollection bundles)
 {
    BundleTable.EnableOptimizations = true;
    string version = string.Format("{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));
    bundles.UseCdn = true;
    var cdnUrl = "CDN url"+ "{0}?" + version;
    
    bundles.Add(new ScriptBundle("~/bundles/bootstrap", string.Format(cdnUrl, "bundles/bootstrap")).Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/moment.min.js",
                      "~/Scripts/bootstrap-datetimepicker.min.js",
                      "~/Scripts/respond.js"));
 
 }
并将这一行添加到
Global.asax.cs
应用程序_BeginRequest
中,以允许交叉原点

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "CDN url");
请尝试以下代码:

bundles.UseCdn=true; 添加(新脚本包(“~/bundles/jquery”)http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js)包括( “~/Scripts/jquery-{version}.js”)


并在debug=“false”模式下运行应用程序,或使用BundleTable.EnableOptimizations=true

请您解释一下,这不会产生所需的散列。