MVC4 style bundle giving 403

.Netasp.net MvcRazorasp.net Mvc-4Bundling and-Minification

.Net Problem Overview


When bundling/minification is enabled, some of my bundles seem to have an invalid URL in the browser (ending with a /), and IIS gives a 403 forbidden error, as if trying to list a folder's contents.

There's no difference in the way my bundles are set up - they are not .min.css, access permissions are correct etc.

.Net Solutions


Solution 1 - .Net

My bundles were registered as paths which corresponded to an actual folder on the solution, e.g. ~/Content/forum.

This works fine when bundling is turned off (the bundle is included correctly!), but not when bundling is enabled.

The solution is to change the registered name of the bundle to not be the same as anything that exists in the file system.

Solution 2 - .Net

In my case bundle was specified as a directory @Scripts.Render("~/scripts") so IIS did not know how to serve the actual js file, I changed the bundle name to represent a javascript file @Scripts.Render("~/scripts.js") and that fixed it. The same was true for my style bundle.

Solution 3 - .Net

The problem is the naming convention your bundle name should be

("bundles/css") 

This solved my problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKieren JohnstoneView Question on Stackoverflow
Solution 1 - .NetKieren JohnstoneView Answer on Stackoverflow
Solution 2 - .NetmohasView Answer on Stackoverflow
Solution 3 - .NetUsmanView Answer on Stackoverflow