MVC4 style bundle giving 403

28,954

Solution 1

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

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

The problem is the naming convention your bundle name should be

("bundles/css") 

This solved my problem.

Share:
28,954

Related videos on Youtube

Kieren Johnstone
Author by

Kieren Johnstone

Software developer, company director and guitarist. Experience in C#, C++, Java, SQL, various embedded systems, assembler. Enjoy work with algorithms, distributed computing, anything clever or inventive. Familiar with various frameworks, technologies and methodologies; ASP.NET / MVC, WPF, MVVM, strong OOP, design patterns, DI, XML / XSLT, WCF, low-level network protocols, some COM, MFC, unit testing, code optimization and other low-level fun bits.

Updated on July 28, 2022

Comments

  • Kieren Johnstone
    Kieren Johnstone almost 2 years

    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.

  • Kieren Johnstone
    Kieren Johnstone over 11 years
    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
  • VikciaR
    VikciaR almost 11 years
    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.
  • Don Thomas Boyle
    Don Thomas Boyle over 10 years
    what exatcly do you mean the name of the bundle itself?
  • Kieren Johnstone
    Kieren Johnstone over 10 years
    @DonThomasBoyle - are you asking me? I don't use that phrase anywhere
  • Don Thomas Boyle
    Don Thomas Boyle over 10 years
    @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"));
  • jhilden
    jhilden over 9 years
    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.
  • wolfyuk
    wolfyuk over 9 years
    Spot on. This seems to be a bug in the FontAwesome nuget package.
  • Tetsujin no Oni
    Tetsujin no Oni over 9 years
    Also in the select2 nuget package.
  • LuqJensen
    LuqJensen over 5 years
    This solved a lot of headache for me. @WolfyUK is correct. The bug still persists in 2018/19...
  • Matt Slavicek
    Matt Slavicek about 3 years
    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."