Learn how to solve the 404 error you get when you try to run an ASP.NET project with .less files
Every ASP.NET developer must love the web.config file. Seriously, I will write about it some day. :-)
Some time ago, we have faced a very interesting problem in one of our ASP.NET projects. We have decided to use LESS CSS in order to optimize the front-end development and speed up the things a bit. While we knew that we should compile the LESS files before throw it to production we were facing an error during the development phase:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
The reason: IIS doesn’t support .less files by default.
By this time we have 2 solutions: The first one is to call the responsible for the webserver and ask him to add a new MIME type into the IIS. But thanks to the .NET architecture we don't need to do that. All we need to do is to add some extra lines to your web.config, inside , as seen bellow:
<system.webServer> <staticContent> <remove fileExtension=".less" /> <mimeMap fileExtension=".less" mimeType="text/css" /> staticContent> system.webServer>
As you saw it’s simple, clear and useful. Keep in mind that you can use the same method to solve the problem with other non-supported files such as webfonts (.eot, .woof), videos (.mp4, .ogg, .m4v), images (.svg, .svgx) and so on (as Mads Kristensen wrote).