.less 文件在 IIS6 上静态提供.NET 4 MVC3

发布于 2024-12-03 03:07:14 字数 809 浏览 5 评论 0原文

在 .NET 4 MVC3 项目中,我在 IIS6 上运行本地计算机(不要问为什么)。它在 IIS 中具有到 v4 aspnet_isapi.dll 的正确通配符映射,.less 扩展名也是如此。

Web.config 定义了这些 IIS6 和 IIS7 httphandlers。

<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>

浏览 /path/to/nonexisting.less 会抛出一个正确的错误,该错误向我显示 LessCssHttpHandler 正在运行的堆栈跟踪。

浏览到 /path/to/existingfileondisk.less 只是按原样下载原始的 less 文件。对我来说,似乎现有的静态文件处理程序在这里正在运行,尽管我不确定。

我缺少什么(除了新机器;))?

In a .NET 4 MVC3 project I'm running a local machine on IIS6 (don't ask why). It has a proper 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 ;))?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪 2024-12-10 03:07:14

我也遇到了这个问题,下一个解决方案解决了这个问题:

如果您使用的是 IIS 6 或更早版本,或者没有使用 IIS 的集成管道,则需要配置 Web 服务器的设置,以便将 .LESS 文件的请求路由到ASP.NET 引擎(以便它们可以由 .LESS HTTP 处理程序处理)。有关更多详细信息,请阅读 如何 ASP. NET 网页在 Web 服务器上处理

如何配置 IIS6 的步骤:

  1. 右键单击​​网站 ->属性->主目录 ->配置->应用扩展->添加-> :
    • 可执行文件 = asp.net DLL 的路径(例如 c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll )
    • 扩展 = .less
    • 取消选中“验证该文件是否存在”
  2. 配置 Mime 类型:右键单击网站 ->属性-> HTTP 标头 -> MIME 类型 ->新->扩展名 = .less ,MIME 类型 =“text/css”

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”
比忠 2024-12-10 03:07:14

我建议您将 .less 文件全部放在一个文件夹中。假设您在 root 上创建了一个名为 Less 的文件夹。您必须将此行添加到 global.asax 才能使其正常工作:

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

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}");
    ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文