带CDN的ASP.NET MVC多虚拟路径捆绑包 [英] ASP.NET MVC multiple virtualpath Bundle with CDN

查看:76
本文介绍了带CDN的ASP.NET MVC多虚拟路径捆绑包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在ASP.NET MVC 4中添加一些具有CDN功能的捆绑软件。目的是通过同一数据中心中托管的许多其他站点在本地共享内容

I´m trying to add some CDN capable bundle with ASP.NET MVC 4. The purpose is to share content locally by many other sites hosted in the same data center

第一次尝试是:

            bundles.Add(new ScriptBundle("~/bundles/jquery", "http://mysite/Content/js/").Include(
                                                              "http://mycdnsite/Content/js/jquery.unobtrusive-ajax.min.js",
                                                              "http://mycdnsite/Content/js/jquery-migrate-1.2.1.js",
                                                              "http://mycdnsite/Content/js/jquery-{version}.js"));

不幸的是,这是不可能的,因为虚拟路径必须是相对的
(仅相对于应用程序URL(〜/ url)是允许的)

Unfortunatelly, this is not possible, because the virtualPaths must be relative (Only application relative URLs (~/url) are allowed)

然后我尝试了此操作:

        bundles.Add(new ScriptBundle("~/bundles/jquery", "http://mycdnsite/Content/js/").Include(
                                                              "~/jquery.unobtrusive-ajax.min.js",
                                                              "~/jquery-migrate-1.2.1.js",
                                                              "~/jquery-{version}.js"));

但是它没有用,甚至启用了CDN:

But it hasn't worked, even enabling CDN:

BundleTable.EnableOptimizations = true;
bundles.UseCdn = true;

是否可以使用CDN创建多内容捆绑包?

Is it possible to create a multiple content bundle with CDN?

推荐答案

AFAIK,您不能在一个捆绑包中提供多个CDN主机。 ScriptBundle 允许您为捆绑包指定备用URL,捆绑包可能包含多个本地文件。您所使用的语法是正确的。

AFAIK you can't not serve multiple CDN hosts in one bundle. ScriptBundle allows you to specify an alternate URL for the bundle and the bundle could contain several local files. The syntax you have is correct.

bundles.UseCdn = true;
bundles.Add(new ScriptBundle("~/bundles/jquery",
   @"//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.js"
   ).Include(
    "~/Scripts/jquery-{version}.js"));

有两种方法可以解决此问题。

There are a couple of ways to solve this problem.


  1. 每个CDN托管脚本都有一个捆绑包。

  2. 手动创建文件捆绑包并将其上传到您自己的CDN并引用。 / li>
  1. Have one bundle per CDN hosted script.
  2. Manually create a bundle of the files and upload them to your own CDN and reference that.

这篇关于带CDN的ASP.NET MVC多虚拟路径捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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