我的MVC项目有问题。无法使CDN正常工作。我所做的是以下几点: -在Azure网站(https://mycoolcdn.azueedge.net)中配置了CDN -更新了BundleConfig.cs,使其指向CDN -使用CDN地址和UseCDN标志更新了web.config,因此BundleConfig如下所示:
public static class BundleConfig
{
public static string HostingEnvironment = ConfigurationManager.AppSettings["HostingEnvironment"];
public static void RegisterBundles(BundleCollection bundles)
{
bundles.UseCdn = Convert.ToBoolean(ConfigurationManager.AppSettings["CdnEnabled"]);
if (HostingEnvironment == "DEV")
{
bundles.IgnoreList.Clear();
bundles.Add(
new StyleBundle(CreateVirtualPath("/Bundles/App/vendor/css"), CreateCdnPath("/Bundles/App/vendor/css"))
.Include("~/Scripts/toastr/toastr.min.css", new CssRewriteUrlTransform())
.Include("~/Scripts/sweetalert/dev/sweetalert.css", new CssRewriteUrlTransform())
.Include("~/Content/flags/famfamfam-flags.css", new CssRewriteUrlTransform())
.Include("~/Scripts/font-awesome/css/font-awesome.min.css", new CssRewriteUrlTransform())
.Include("~/Scripts/simple-line-icons/css/simple-line-icons.css", new CssRewriteUrlTransform())
.Include("~/Scripts/bootstrap/dist/css/bootstrap.min.css", new CssRewriteUrlTransform())
.Include("~/Scripts/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css", new CssRewriteUrlTransform())
.Include("~/Scripts/bootstrap-table/src/bootstrap-table.css", new CssRewriteUrlTransform())
.Include("~/Scripts/angular-ui-grid/ui-grid.min.css", new CssRewriteUrlTransform())
.Include("~/Scripts/ng-sortable/dist/ng-sortable.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/plugins/fullcalendar/fullcalendar/fullcalendar.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/plugins/jqvmap/jqvmap/jqvmap.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/plugins-md.min.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/components.min.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/components-md.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/fonts.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/layouts/layout4/css/layout.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/layouts/layout4/css/themes/default.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/layouts/layout4/css/custom.min.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/plugins/jquery-nestable/jquery.nestable.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/plugins.min.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/css/plugins/owl-carousel/owl.carousel.css", new CssRewriteUrlTransform())
.Include("~/Content/assets/global/plugins/typeahead/typeahead.css", new CssRewriteUrlTransform())
);
bundles.Add(
new StyleBundle(CreateVirtualPath("/Bundles/jquery"), CreateCdnPath("/Bundles/jquery"))
.Include(
"~/Scripts/jquery/dist/jquery.min.js"
));
BundleTable.EnableOptimizations = true;
}
//CDN methods implementation
private static string CreateVirtualPath(string path)
{
return $"~{path}";
}
private static string CreateCdnPath(string path)
{
string CdnURL = ConfigurationManager.AppSettings["CdnURL"];
return $"{CdnURL}{path}";
}
}
问题有两个。即使将'debug'设置为False并且UseCDN = true,本地主机上的文件仍来自本地主机。在本地测试解决方案的正确方法是什么? 第二个问题,我不确定到CDN的链接是否正确。就我而言,应用程序将在“ https://mycoolcdn.azueedge.net//Bundles/App/vendor/css”中查找文件,而实际情况却有所不同(取决于资源),正如您从代码中看到的那样。对于具有混合链接的大型捆绑包,什么是正确的方法?