Search code examples
asp.net-mvcasp.net-mvc-4resourcebundleasp.net-optimization

Why is resource bundling being redirected in my ASP MVC4 app?


I'm using the RC and I've checked everything is up to date via NuGet. In my global.asax.cs ive got:

BundleTable.Bundles.AddDefaultFileExtensionReplacements();
BundleTable.Bundles.AddDefaultIgnorePatterns();
BundleTable.Bundles.AddDefaultFileOrderings();

Bundle scripts = new Bundle("~/Scripts");
scripts.IncludeDirectory("~/Scripts", "*.js");
BundleTable.Bundles.Add(scripts);

Bundle css = new Bundle("~/Content/css");
css.IncludeDirectory("~/Content/css", "*.css", false);
BundleTable.Bundles.Add(css);

I've tried a few different configurations of this with no improvement.

Then in my layout ive got:

<link href="@BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="@BundleTable.Bundles.ResolveBundleUrl("~/Scripts")"> </script>

When the page loads its got decent looking urls:

<link href="/Content/css?v=QAsFYXHCbnaU70oGVxpgi9py9iKQrT9C4BVNdHa7xoI1" rel="stylesheet" type="text/css" />

But that url redirects to:

/Content/css/

Which returns a 404 not found error...

bundle redirection...

Anybody got any ideas?


Solution

  • The bundle module logic that decides whether or not to handle a request, will not takeover requests to existing files or directories. So that's why your bundle requests don't work when they live at the same virtual path as an existing directory (or file).