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!

8
  • 1
    May be your path to the bundled files is different than the one that should be... Mar 13, 2013 at 18:46
  • is the runtime set to 4.0 or 4.5? Check web.config. You using VS2012 or 2010?
    – C0L.PAN1C
    Mar 13, 2013 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, 2013 at 22:14
  • What does your BundleConfig look like? Also, is your site deployed to the root of the site? Mar 13, 2013 at 22:20
  • 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. Mar 13, 2013 at 22:52

4 Answers 4

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.

1
  • 1
    i had the same issue to access font awesome fonts, for other solutions try these links which deals with StyleBundle virtualpath: Link 1 , Link 2, Link 3, Link 4 , hope this helps someone.
    – Shaiju T
    Feb 25, 2016 at 9: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.

6
  • 1
    The documentation says it will reject a request containing multiple periods; which infers that a single period should be ok.
    – gerrod
    Nov 12, 2013 at 0: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, 2013 at 7: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, 2013 at 2: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, 2013 at 5:51
  • Hi @xinqiu; yes, that sounds more plausible, thanks for fixing it up!
    – gerrod
    Nov 18, 2013 at 23:17
5

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.