简体   繁体   English

未使用无点文件的样式

[英]Styles from dotless files not used

We have a website that makes use of .less files (the pre-compiler dotless has been installed using nuget), however the .less files are not handled as css files. 我们有一个使用.less文件的网站(使用nuget安装了预编译器dotless),但是.less文件不作为css文件处理。

When trying to view the website in firefox, the console gives use the following error: The stylesheet http:// website/css/init.less was not loaded because its MIME type, "application/octet-stream", is not "text/css". 当试图在firefox中查看网站时,控制台使用以下错误:未加载样式表http:// website / css / init.less,因为其MIME类型“application / octet-stream”不是“text” / CSS”。

Our dotless file is trying to import more files: 我们的无点文件正在尝试导入更多文件:

@import "imports";
..

But even replacing this text with css code, the styles are still not applied. 但即使用css代码替换此文本,样式仍未应用。 But if I go to that file in Visual Studio, it is displaying all the css from the files that are imported. 但是,如果我在Visual Studio中转到该文件,它将显示导入文件中的所有css。

If you're using the dotLess handler to process and serve your .less files on the fly (which is fine for debugging, but you might want to consider pre-compiling for release), you need to ensure that you also send them down with the correct mimetype. 如果您正在使用dotLess处理程序来动态处理和提供.less文件(这对于调试很好,但您可能需要考虑预编译以进行发布),您需要确保也将它们发送给正确的mimetype。

You can do this either at the server level in IIS Admin (if you're likely to using this for multiple sites on the machine), or at the local site level via the web.config - note that you can't do both, IIS will complain that there are multiple entries for the file extension. 您可以在IIS Admin中的服务器级别执行此操作(如果您可能将此用于计算机上的多个站点),也可以通过web.config在本地站点级别执行此操作 - 请注意,您不能同时执行这两项操作, IIS会抱怨文件扩展名有多个条目。

To do this in the web.config, within the <configuration><system.webServer> element add the following elements: 要在web.config中执行此操作,请在<configuration><system.webServer>元素中添加以下元素:

<staticContent>
  <mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent>

Obviously, if you've already got some mimemap entries, just add the mimemap there. 显然,如果你已经有一些mimemap条目,只需在那里添加mimemap。

This will ensure that IIS claims that the .less files served from the handler as CSS rather than the default application/octect-stream . 这将确保IIS声称.less文件从处理程序作为CSS而不是默认的application/octect-stream

If that's still not serving them as processed, there are a couple of other things you'll need to check: 如果仍未将其作为处理对象提供,则还需要检查以下其他一些事项:

  1. Ensure that the handler is correctly registered in both the <system.webserver><handlers> and <system.web><httpHandlers> sections (depending on the version of IIS you're using: 确保在<system.webserver><handlers><system.web><httpHandlers>部分中正确注册了<system.webserver><handlers> (具体取决于您使用的IIS的版本:
    <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
    and
    <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
  2. Ensure that IIS is configured to send all requests through the ASP.NET handlers configured in step 1. By default, .less files are probably being considered "static files" and will only be handled by the StaticFileModule. 确保将IIS配置为通过步骤1中配置的ASP.NET处理程序发送所有请求。默认情况下, .less文件可能被视为“静态文件”,并且只能由StaticFileModule处理。
    在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM