Why is my CSS bundling not working with a bin deployed MVC4 app?

ProfK picture ProfK · Aug 16, 2012 · Viewed 133.3k times · Source

I have bin deployed an MVC4 application to my hosting provider, based on advice given here and one or two on-the-fly fixes, but the most immediately apparent problem is that the bundling for css doesn't work. When I replace the bundle ref with explicit file refs, my css works again.

I am using a standard MVC4 RTM project template from VS2012. The provider is running IIS 7.5 and ASP.NET 4, and my previous MVC3 version of the same app worked fine. I am guessing I have grabbed a dependency somewhere of too low a version, and this might also contribute to my area based action link problem.

Technical symptoms are:

The line @Styles.Render("~/Content/css") renders as <link href="/Content/css?v=" rel="stylesheet"/>

Answer

cdeutsch picture cdeutsch · Nov 28, 2012

UPDATE 11/4/2013:

The reason why this happens is because you have .js or .css at the end of your bundle name which causes ASP.NET to not run the request through MVC and the BundleModule.

The recommended way to fix this for better performance is to remove the .js or .css from your bundle name.

So /bundle/myscripts.js becomes /bundle/myscripts

Alternatively you can modify your web.config in the system.webServer section to run these requests through the BundleModule (which was my original answer)

<modules runAllManagedModulesForAllRequests="true">
  <remove name="BundleModule" />
  <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>

Edit: I also noticed that if the name ends with 'css' (without the dot), that is a problem as well. I had to change my bundle name from 'DataTablesCSS' to 'DataTablesStyles' to fix my issue.