开发者

.less files are statically served on IIS6 + .NET 4 MVC3

In a .NET 4 MVC3 project I'm running a local machine on IIS6 (don't ask why). It has a p开发者_运维知识库roper wildcard mapping in IIS to the v4 aspnet_isapi.dll, and the same goes for the .less extension.

Web.config has these IIS6 and IIS7 httphandlers defined.

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

<system.webServer>
  <handlers>
    <add name="less" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.less" verb="*" />
  </handlers>
</system.webServer>

Surfing to /path/to/nonexisting.less throws a proper error which shows me a stacktrace that the LessCssHttpHandler is in action.

Surfing to /path/to/existingfileondisk.less just downloads the original less file as is. To me it seems that an existing static file handler is in action here, though I'm not sure.

What am I missing (apart from new machine ;))?


I also encountered this problem, and next solution fixed the problem:

If you are using IIS 6 or earlier or are not using IIS's integrated pipeline, you'll need to configure your web server's settings so that requests for .LESS files are routed to the ASP.NET engine (so that they can be processed by the .LESS HTTP Handler). For more details read How ASP.NET Web Pages are Processed on the Web Server

Steps how to configure IIS6:

  1. Right Click on the Web Site -> Properties -> Home Directory -> Configuration -> Application extensions -> Add -> :
    • Executable = path to the asp.net DLL (f.e. c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll )
    • Extention = .less
    • Uncheck “Verify that file exist”
  2. Configure Mime Type: Right Click on the Web Site -> Properties -> HTTP Headers -> MIME types -> New -> Extension = .less , MIME type =”text/css”


I suggest you to put your .less files all inside a folder. Let's say you created a folder named Less on root. You have do add this line to global.asax to make it work:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("Less/{*path}");
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜