I would like to have define a bundle like this:
bundles.Add(
new StyleBundle("~/style.css").Include(
//...
));
If the bundle name is just "~/style"
this works, but with the file extension it always returns a 404. I suspect the server searches for CSS and JS files on the drive and ignores the bundling system, but I can't find anyone else who is trying to include file extensions in bundle names. Is this possible to do without something like a URL rewrite?
You could add the following to your <system.webServer>
section in web.config:
<modules runAllManagedModulesForAllRequests="true" />
This will ensure that requests for static resources such as .js
and .css
will pass through the managed modules and be intercepted by ASP.NET MVC.
As an alternative to enabling runAllManagedModulesForAllRequests
for all requests you could configure them only for the urls you need to use. So inside the <handlers>
add the following:
<handlers>
<!-- ... -->
<add name="scriptBundle" verb="*" path="script.js" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
<add name="cssBundle" verb="*" path="style.css" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
</handlers>