ASP.NET MVC framework 4.5 CSS bundle does not work on the hosting
asp.net Mvcasp.net Mvc-4Appharborasp.net Optimizationasp.net Mvc Problem Overview
I am runing an App on app harbor written in MVC4.
A bundle of css files doesn't work. In my local computer in debug mode I see the code of the App and I see the files. The App works as expected.
<link href="/Content/css/home/basic-jquery-slider.css" rel="stylesheet"/>
<link href="/Content/css/home/Home.css" rel="stylesheet"/>
When I upload the app to Appharbor I see the bundle in the code but the App doesn't work.
<link href="/Content/css/home?v=zhVOIpUNuvCOZhJyBcQWpMlozayor4te6k-pM29wHqI1" rel="stylesheet"/>
When I browse that link in the href
I get 403 - Forbidden: Access is denied.
How to troubleshoot this?
asp.net Mvc Solutions
Solution 1 - asp.net Mvc
My guess is that the path Content/css
exists on disk in your app. In this case IIS would be handling the request, not MVC.
Make sure that the virtual path for the bundle (the parameter of the StyleBundle constructor) doesn't match a folder in the file system.
From the comments:
> "A good convention to follow when creating bundles is to include > "bundle" as a prefix in the bundle name. This will prevent a possible > routing conflict."
Solution 2 - asp.net Mvc
This issue is by default .NET does not "process" requests that have a .js or .css extension.
There are two fixes for this (you only need to do ONE)
A) Remove the extensions from the bundle names. (recommended) This will cause .NET to process the request and run it through the BundleModule.
B) Add this to your web.config in the system.webServer section which will cause .NET to run .js and .css requests through the BundleModule.
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
Big shout out to Ray Moro who figured out the actual cause and shared it with me on my blog: http://blog.cdeutsch.com/2012/11/fixing-404-errors-for-aspnet-mvc-apps.html
Solution 3 - asp.net Mvc
Happened with me too, when I tried deploying my ASP.NET MVC app on AppHarbor.
I had a stylesheet bundle with the name
@Styles.Render("~/Content/bootstrap")
and the folder structure was
> -- Content > > -- Content \ Bootstrap \ ...
By just changing the bundle name to "~/Content/bootstrap-css"
my issue got resovled.
Solution 4 - asp.net Mvc
I know I'm 4 years late to this question but this worked for me.
public static void RegisterBundles(BundleCollection bundles)
{
...
BundleTable.EnableOptimizations = true; // Added this
}
Solution 5 - asp.net Mvc
403 error solved. here is a detailed explanation and solution for 403 error.
[The solution][1] is demonstrated for CSS bundle. However it also applies to JavaScript.
http://www.mvccentral.net/Story/Details/articles/kahanu/stylebundle-403-error-solved
[1]: http://www.mvccentral.net/Story/Details/articles/kahanu/stylebundle-403-error-solved
In a nutshell, make sure that the virtual path [Script | Style]Bundle("~/content/[script | css]")
doesn't match a folder in the file system (e.g. C:\approot\Content\[script | css]
) instead [Script | Style]Bundle("~/content/[scriptDiff | cssDiff]")
Solution 6 - asp.net Mvc
I solved the issue by adding below line of code at BundleConfig class
BundleTable.EnableOptimizations = false;
Solution 7 - asp.net Mvc
What I do is very simple,
I add "js" at the end of ScriptBundle like so: new ScriptBundle("/bundles/appjs")
And I add "css" at the end of StyleBundle like so: new StyleBundle("/content/appcss")
My folder names never end with "js" or "css".
That should do it.
Solution 8 - asp.net Mvc
This applies to the 'ScriptBundle class' too, ensure that the 'parameter name' to the constructor does not match a path in web application file system. Remember that IIS will try to serve up the file/request.
Solution 9 - asp.net Mvc
The problem can also come from the file being encrypted. This occurred to me when I downloaded BootStrap and used the supplied files. They showed green in Windows explorer and worked fine in Visual Studio, but when deployed, I got a 403 error.
You can see if they are encrypted by going to properties, then advanced properties and there is an encypted checkbox.
Uncheck and it will no longer be a problem.
Solution 10 - asp.net Mvc
I have the same problem with that (403 Forbidden) error. In my case the reason is proxy server in my organization blocks my css file. Css file name matches one of block rules.
Solution 11 - asp.net Mvc
I found out the file bootstrap.css wasn't in the content folder, so I looked for it in the packages and pasted there.. it worked!