Reputation: 21
For an MVC 4 project, I have a requirement to include/bundle content files that reside outside the MVC project e.g. somewhere in a CDN.
This works:
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/Css/site.css"));
This does not work:
bundles.Add(newStyleBundle("~/Content/css").Include("D:/Media/Styles/Css/site.css"));
The error I get is:
The URL 'D:/Media/Styles/Css/site.css' is not valid. Only application relative URLs (~/url) are allowed. Parameter name: virtualPaths
In short, is it at all possible to have asset files residing outside the project's Content folder, for example when using a CDN? if so, what is the best approach?
Upvotes: 2
Views: 5269
Reputation: 4701
You can only use relative paths and CDN. The resources can be outside the Content folder, so you can have them in a different folder within your site.
You can also use a CDN like this:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.UseCdn = true; //enable CDN support
//add link to jquery on the CDN
var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
Upvotes: 3