Thursday, May 6, 2010

Fix dotless for IIS 7 with integrated pipeline mode

Recently I installed ASP.Net MVC site with dotless on production server. Site worked well under Visual Studio built-in web server but after installation on IIS css styles were not applied. In our project we use file with .less.css extension in order to keep intellisense, syntax highlighting and in order to avoid problems with non-standard file extensions on web server. As documentation says we need to register dotless handler for such files in web.config:

   1: <configSections>
   2:     ....
   3:     <section name="dotless"
   4:         type="dotless.Core.configuration.DotlessConfigurationSectionHandler,
   5:             dotless.Core, Version=1.0.0.1, Culture=neutral"/>
   6: </configSections>
   7: <system.web>
   8:     <httpHandlers>
   9:         ...
  10:         <add type="dotless.Core.LessCssHttpHandler,dotless.Core"
  11:             validate="false" path="*.less.css" verb="*"/>
  12:     </httpHandlers>
  13: </system.web>
  14: ...
  15: <dotless minifyCss="false" cacheEnabled="false"/>

And as I said it worked for built-in web server. But when I entered URL http://example.com/css/styles.less.css on production – I get original file without any modifications. I.e. all dotless artifacts like variables (@foo), mixins, etc. were not expanded to valid css.

The problem is that for integrated pipeline mode we need to add one more record into <system.webServer> section in web.config file:

   1: <system.webServer>
   2:     ...
   3:     <handlers>
   4:         ...
   5:         <add name="dotless"
   6:             type="dotless.Core.LessCssHttpHandler,dotless.Core"
   7:             path="*.less.css" verb="*"/>
   8:     </handlers>
   9: </system.webServer>

After this dotless file was successfully transformed into valid css.

Update 2010-05-08: jamesfoster notified that he updated http://www.dotlesscss.org with it

2 comments:

  1. Hey, I know this was posted a long time ago, but I just wanted to say thanks!

    ReplyDelete
  2. it's always nice to hear ) thanks for your comment I've found that URLs on dotlesscss site were outdated in the post: com domain was used, while now dotlesscss uses org domain. Fixed it now.

    ReplyDelete