Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 962
Tim Avatar asked Jun 27 '12 21:06

Tim


People also ask

How do you override the bundling setting of web config?

To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.

What is bundle config in asp net?

What Is Bundling. In a web application when we reference different files of JavaScripts and style-sheets, the browser sends individual requests to the server to fetch them. From ASP . NET 4.5 onward the developer will have the ability to create bundles of . js and .

What is difference between bundling and minification?

Both bundling and minification are the two separate techniques to reduce the load time. The bundling reduces the number of requests to the Server, while the minification reduces the size of the requested assets.

What are the different ways for bundling and minification in asp net core?

Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.


1 Answers

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.

like image 149
Beygi Avatar answered Sep 23 '22 01:09

Beygi