.LESS 文件上的智能感知

发布于 2024-11-03 19:52:08 字数 839 浏览 0 评论 0原文

我将 LESS 引入现有的 ASP.NET Web 表单应用程序中。为了让智能感知正常工作,我决定设置 LessCssHttpHandler 来拦截以 .less.css 结尾的文件的请求。这样,Visual Studio 仍然认为我们正在处理 CSS 文件。我通过将以下行添加到 web.config 文件中来实现此目的:

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

为了使其正常工作,我必须调整 IIS 设置,以便 ASP.NET 框架处理 .css 文件。不幸的是,通过这样做,现在我现有的 .css 文件(这些文件不是由无点 HTTP 处理程序处理的,因为它们不以 .less.css 结尾)不返回任何内容。这是有道理的,因为 ASP.NET 框架在看到具有该扩展名的文件时并不真正知道该怎么做。

除了上面的处理程序之外,是否还可以设置某种基本 HTTP 处理程序来处理普通的 .css 文件?像这样的东西:

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

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

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

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

发布评论

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

评论(3

恋竹姑娘 2024-11-10 19:52:08

看起来 StaticFileHandler 就是我正在寻找的。这就是我们最终将其添加到 web.config 中的 httpHandlers 节点的方式:

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

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" />
时光无声 2024-11-10 19:52:08

我们使用 Chirpy 来支持 LESS(以及我们的 google 闭包编译器支持)。它允许您为 LESS 配置文件扩展名,例如 .less.css,然后您就可以获得 Intellisense 支持。

它不在运行时进行翻译,而是在 Visual Studio 中的设计时进行翻译。当您编辑并保存 LESS 文件时,Chirpy 会启动并处理生成 css 文件的 LESS 文件。这样我们就不必将 css 文件服务交给 ASP.NET。

We use Chirpy for our LESS support (as well as our google closure compiler support). It allows you to configure file extensions for LESS, such as .less.css, and then you can have Intellisense support.

It doesn't do translation at runtime but rather at design time within visual studio. When you edit and save the LESS file, Chirpy kicks in and processes the LESS file which generates the css file. This way we avoid having to hand off css file serving to ASP.NET.

笑梦风尘 2024-11-10 19:52:08

我倾向于使用控制台编译器并将 less 文件重命名为 .css
httphandler 通常只适用于在 CSS 中需要参数的人。

I tend to use the console compiler and rename the less file to .css
The httphandler is usually only for people who need parameters in their CSS.

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