104

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.

2

3 Answers 3

242

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.

10
  • 22
    Note also if the CSS files refer to imagery or other files relative to the CSS, make sure the bundle filename is something under the folder containing the actual CSS. For example, ~/Content/myfolder/bundle if CSS is under Content/myfolder Dec 7, 2012 at 8:19
  • 1
    I had two bundles: ~/Content/kendo (for css) and ~/bundles/kendo (for scripts). So: 403 error. When I changed name one of them - problem gone. Thanks.
    – VikciaR
    May 22, 2013 at 12:10
  • 1
    @KierenJohnstone sorry about not being specific, "Change the registered name of the bundle" what do you mean with that? - I assumed the name of the bundle WE assign. Like (the bolded part) -> bundles.Add(new StyleBundle( "~/Content/css" ).Include("~/Content/site.css")); Aug 21, 2013 at 20:55
  • 1
    Spot on. This seems to be a bug in the FontAwesome nuget package.
    – wolfyuk
    Oct 17, 2014 at 8:01
  • 1
    Also in the select2 nuget package. Jan 21, 2015 at 14:01
4

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.

3

The problem is the naming convention your bundle name should be

("bundles/css") 

This solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.