Search code examples
asp.netlesshttphandlerdotless

Intellisense on .LESS files


I'm introducing LESS into an existing ASP.NET web forms application. In order to get intellisense to work, I decided to set up the LessCssHttpHandler to intercept requests for files ending in .less.css. That way, Visual Studio still thinks we're dealing with a CSS file. I did this by adding the following line to my web.config file:

<add type="dotless.Core.LessCssHttpHandler, dotless.Core" 
     validate="false" path="*.less.css" verb="*" />

In order to get this to work, I had to tweak my IIS settings so that .css files get handled by the ASP.NET framework. Unfortunately, by doing so, now my existing .css files (which aren't handled by the dotless HTTP handler since they don't end in .less.css) aren't returning any content. This makes sense since the ASP.NET framework doesn't really know what to do when it sees a file with that extension.

Is there some sort of base HTTP handler I can set up in addition to the one I have above to handle normal .cssfiles? Something like:

<add verb="*" path="*.css" type="insert some base HTTP handler here that will simply return the contents of the file" />

Solution

  • Looks like the StaticFileHandler is what I was looking for. This is how we ended up adding it to our httpHandlers node in web.config:

    <add verb="*" path="*.less.css" validate="false" type="dotless.Core.LessCssHttpHandler, dotless.Core, Version=1.1.0.7, Culture=neutral, PublicKeyToken=96B446C9E63EAE34, processorArchitecture=MSIL" />
    <add verb="*" path="*.css" type="System.Web.StaticFileHandler" />