19

I have a project that works with bundling when you run it from within visual studio. However, after you do a deployment, the bundling handler never seems to pick up the route. It ends up going to the static file handler instead, which returns a 404 response.

Any ideas? I see the optimization assembly in the bin of the website under IIS.

It's using the 4.0 app pool and integrated mode.

I'm wondering if anyone has any ideas or suggestions?

Thanks

----- update based on questions -----

VS2012

targetFramework="4.5"

I also added some code into the view to show which modules were loaded and I can see the bundle module listed there.

BundleConfig is the default provided when using the Internet Application MVC4 project template.

The site is being deployed into the root. It's odd as when I set EnableOptimizations = true (due to running in debug mode via visual studio F5), it works perfect! I can navigate to content/css and it spits out the combined css.

I deploy it over and everything else works, but bundling!

Mike
  • 1,300
  • 3
  • 14
  • 20
  • 1
    May be your path to the bundled files is different than the one that should be... – Bhushan Firake Mar 13 '13 at 18:46
  • is the runtime set to 4.0 or 4.5? Check web.config. You using VS2012 or 2010? – apollosoftware.org Mar 13 '13 at 18:48
  • I don't see how the path could be wrong considering I'm doing a publish to my IIS folder and everything else loads fine (views, layouts, images). If I manually reference the css file /content/site.css it loads. But when I hit /content/css the bundlemodule seems to not intercept the call and load the bundled css content! – Mike Mar 13 '13 at 22:14
  • What does your BundleConfig look like? Also, is your site deployed to the root of the site? – Erik Funkenbusch Mar 13 '13 at 22:20
  • updated question to include answers – Mike Mar 13 '13 at 22:41
  • 1
    That's the way it's supposed to work. /css doesn't work in debug mode, instead, `Styles.Render("~/Content/css")` renders links to the individual css file(s) in debug mode. That's why you're supposed to use `Styles.Render()` rather than directly call it. – Erik Funkenbusch Mar 13 '13 at 22:52
  • I have EnableOptimizations set to true, so that way I could ensure it was working in visual studio. It does work. So I can hit /content/css (because it's bundling even when in debug mode). However, going to /content/css (in browser, I'm not linking to it. I'm using Styles.Render()) when it's hosted in IIS fails. – Mike Mar 13 '13 at 23:17
  • To be clear, this is a default mvc4 internet application that I deployed. The only difference being is that I specified EnableOptimizations = true so that I could test while in visual studio to see if the bundler failed there too. It doesn't. So the layout is using the correct syntax etc for including the style sheet(s). – Mike Mar 13 '13 at 23:18

4 Answers4

26

I've just hit (and solved) this problem.

Make sure your bundle's virtual path can't be confused for an existing directory or actual file name. In my case, I'd coded it as:

bundles.Add(new ScriptBundle("~/bundles/main.js").Include( ...

But when I changed it to

bundles.Add(new ScriptBundle("~/bundles/main").Include( ... 

it all started working.

user2320070
  • 261
  • 2
  • 4
  • 1
    i had the same issue to access font awesome fonts, for **other solutions** try these links which deals with `StyleBundle` **virtualpath**: [Link 1](http://www.mvccentral.net/story/details/articles/kahanu/stylebundle-403-error-solved) , [Link 2](http://forums.asp.net/t/1774324.aspx?MVC4+css+bundling+and+image+references), [Link 3](http://ericpanorel.net/2013/10/25/font-awesome-4-0-mvc-bundling-and-minification/), [Link 4](http://jameschambers.com/2014/08/adding-some-font-awesome-to-mvc-and-bootstrap/) , hope this helps someone. – Shaiju T Feb 25 '16 at 09:35
13

Updated Answer on 11/17/2013 This is caused by the fact that the default MVC routing only handles * instead of * . *, i.e. IIS or IIS Express's applicationhost.config has the following:

            <add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />

So to workaround it, we can add the following to the web.config:

      <system.webServer>
        <handlers>      
          <add name="UrlRoutingHandler" 
               type="System.Web.Routing.UrlRoutingHandler, 
                     System.Web, Version=4.0.0.0, 
                     Culture=neutral, 
                     PublicKeyToken=b03f5f7f11d50a3a" 
               path="/bundles/*" 
               verb="GET"/>      
        </handlers>
      </system.webServer>

For more information, you can reference the following: http://weblogs.asp.net/owscott/archive/2013/01/16/handing-mvc-paths-with-dots-in-the-path.aspx ASP.NET MVC Url Route supporting (dot)

Old wrong answer: Basically, DOT is generally not allowed in virtual path when IIS parse URLs. This a Link mentioned the following URLScan AllowDotInPath parameter: By default, this option is set to 0. If this option is set to 0, URLScan rejects any request that contains multiple periods (.). This prevents attempts to disguise requests for dangerous file name extensions by putting a safe file name extension in the path information or query string portion of the URL. For example, if this option is set to 1, URLScan might permit a request for http:// servername/BadFile.exe/SafeFile.htm because it interprets it as a request for an HTML page, when it is actually a request for an executable (.exe) file with the name of an HTML page in the PATH_INFO area. When this option is set to 0, URLScan may also deny requests for directories that contain periods.

Community
  • 1
  • 1
xinqiu
  • 795
  • 6
  • 13
  • 1
    The documentation says it will reject a request containing **multiple** periods; which infers that a single period should be ok. – gerrod Nov 12 '13 at 00:34
  • 1
    @gerrod, the last sentence indicated: When this option is set to 0, URLScan may also deny requests for directories that contain periods. With the how the bundling work, it will add some generated hashing suffix to the generated URL. So it will appear there is a dot in the virtual directory. Thus it won't work. – xinqiu Nov 13 '13 at 07:17
  • Uhm, no, that's still not right. The hash gets appended as a query string parameter, e.g. `bundles/main.js?v={hash}`. I've literally just tried this, and you're **right** that having more than one period in the path will cause the URLScan to reject the request; but having a single period is fine. – gerrod Nov 14 '13 at 02:28
  • @gerrod, thanks, you are right, my old answer is wrong. I've updated the answer. Thanks again, and if you see this is correct, please approve the answer. Thanks! – xinqiu Nov 18 '13 at 05:51
  • Hi @xinqiu; yes, that sounds more plausible, thanks for fixing it up! – gerrod Nov 18 '13 at 23:17
  • Close. It updated my bundles' errors from 404s to 500 internal server errors. – AuRise Feb 18 '16 at 23:34
5

Even I got the same error. Adding <modules runAllManagedModulesForAllRequests="true" /> under <system.webServer> in web.config file solved the problem.

vineel
  • 3,483
  • 2
  • 29
  • 33
0

I had the same problem even with sample MVC application. I saw the default template bundles the style-sheet with css name which i guess IIS does not likes resulting in 404 error.

Changing the bundle name from css to APPCSS will resolve the issue for me.

chaitu301
  • 69
  • 13