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.

Charles
  • 50,943
  • 13
  • 104
  • 142
Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • 3
    possible duplicate of [ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting](http://stackoverflow.com/questions/12081255/asp-net-mvc-framework-4-5-css-bundles-does-not-work-on-the-hosting) – slolife May 24 '13 at 21:01
  • Possible duplicate of [ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting](http://stackoverflow.com/questions/12081255/asp-net-mvc-framework-4-5-css-bundles-does-not-work-on-the-hosting) – Michael Freidgeim Jan 17 '17 at 23:41

3 Answers3

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.

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • 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` – Kieren Johnstone Dec 07 '12 at 08: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 '13 at 12:10
  • what exatcly do you mean the name of the bundle itself? – Don Thomas Boyle Aug 21 '13 at 16:37
  • @DonThomasBoyle - are you asking me? I don't use that phrase anywhere – Kieren Johnstone Aug 21 '13 at 20:48
  • 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"));` – Don Thomas Boyle Aug 21 '13 at 20:55
  • my bundle name was "~/Content/css" and a directory /Content/css already existed. I changed the bundle name to "~/Content/cssScripts" and it was all good. – jhilden Sep 09 '14 at 14:02
  • 1
    Spot on. This seems to be a bug in the FontAwesome nuget package. – wolfyuk Oct 17 '14 at 08:01
  • 1
    Also in the select2 nuget package. – Tetsujin no Oni Jan 21 '15 at 14:01
  • This solved a lot of headache for me. @WolfyUK is correct. The bug still persists in 2018/19... – LuqJensen Dec 30 '18 at 13:26
  • This is what worked for me "The solution is to change the registered name of the bundle to not be the same as anything that exists in the file system." – Matt Slavicek Mar 04 '21 at 14:24
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.

mohas
  • 1,911
  • 1
  • 16
  • 20
3

The problem is the naming convention your bundle name should be

("bundles/css") 

This solved my problem.

Usman
  • 121
  • 2
  • 6