MVC4 style bundle giving 403
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.
Related videos on Youtube
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, 2022Comments
-
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.
-
slolife almost 11 yearspossible duplicate of ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting
-
Michael Freidgeim over 7 yearsPossible duplicate of ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting
-
-
Kieren Johnstone over 11 yearsNote 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 underContent/myfolder
-
VikciaR almost 11 yearsI 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 over 10 yearswhat exatcly do you mean the name of the bundle itself?
-
Kieren Johnstone over 10 years@DonThomasBoyle - are you asking me? I don't use that phrase anywhere
-
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 over 9 yearsmy 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 over 9 yearsSpot on. This seems to be a bug in the FontAwesome nuget package.
-
Tetsujin no Oni over 9 yearsAlso in the select2 nuget package.
-
LuqJensen over 5 yearsThis solved a lot of headache for me. @WolfyUK is correct. The bug still persists in 2018/19...
-
Matt Slavicek about 3 yearsThis 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."