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

2

7

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?

Holey answered 27/6, 2012 at 21:19 Comment(0)
C
4

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).

Constrictor answered 29/6, 2012 at 23:14 Comment(0)
M
6

The ~/Scripts and ~/Content/css virtual-path already exists on disk, so you need to make them some virtual-url, lets say ~/Scripts/js, and ~/Content/styles that's it, it's fine now.

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

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

Also in MVC4 the Routing, Bundles, and Filters configuration has been moved to the

~/App_Start/(RouteConfig, BundleConfig, FilterConfig).cs

so check that you have those, if so then write your configurations there.

Mohammed answered 27/6, 2012 at 22:28 Comment(1)
It looks like it was the virtual paths. I'm sure I've seen some examples using these paths!Holey
C
4

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).

Constrictor answered 29/6, 2012 at 23:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.