CSS 如何将 *.less 添加到 IIS 7.0?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7319555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add *.less to IIS 7.0?
提问by Safran Ali
I have set up a virtual application on my localmachine and it is running but it's not loading the CSS file. And I am using the lessCSSfor styling my application and I think the reason here for not loading the css here is that LESSCSS style sheet uses .less extension.
我已经在我的本地机器上设置了一个虚拟应用程序并且它正在运行但它没有加载 CSS 文件。我正在使用lessCSS来设置我的应用程序的样式,我认为这里不加载css的原因是LESSCSS样式表使用了.less扩展名。
So what to do in order to read *.less file extension?
那么如何才能读取 *.less 文件扩展名?
回答by Saeed Neamati
There is no need to add a handler. Just add a MIME type (now known as Internet Media Type) for .less
and set the MIME type to text/css
.
无需添加处理程序。只需为它添加一个 MIME 类型(现在称为 Internet 媒体类型).less
并将 MIME 类型设置为text/css
.
Web servers see the extension of requests (just like extensions of files). If they know the extension, they serve the file, and add an HTTP Header Field to indicate that the content of the file is in which format. For example, when they serve static HTML files, they add Content-Type: text/html
header field. This way, browsers can understand to use which application for processing the body of response.
Web 服务器看到请求的扩展名(就像文件的扩展名)。如果他们知道扩展名,他们就会提供文件,并添加一个 HTTP 头字段来指示文件的内容采用哪种格式。例如,当他们提供静态 HTML 文件时,他们会添加Content-Type: text/html
标题字段。这样,浏览器就可以了解使用哪个应用程序来处理响应体。
If web servers don't know the request extension, they search to see if there is already another application installed on them which knows the extension. If there is another application, then they let that application serve the file.
如果 Web 服务器不知道请求扩展名,它们会搜索以查看是否已经安装了另一个知道该扩展名的应用程序。如果有另一个应用程序,则他们让该应用程序提供文件。
You can think of this example to fully understand what happens:
你可以想到这个例子来完全理解发生了什么:
You go to a restaurant, (you are the HTTP request
). You ask for a pizza (pizza is the extension). The chef knows how to serve pizza, thus it serves you.
你去一家餐馆,(你是HTTP request
)。你要一个比萨(比萨是扩展)。厨师知道如何提供比萨饼,因此它为您服务。
Now consider that you go to the same restaurant another time, and ask for Bomyhoor
(a fake food). Chef doesn't know how to cook and serve that. He/she asks other cooks to see if there is already someone else in the kitchen (kitchen is the web server) who knows how to cook that? If someone knows ho to cook Boomyhoor
, then he/she serves you.
现在想想你又去同一家餐馆,并要求Bomyhoor
(假食品)。厨师不知道如何烹饪和服务。他/她询问其他厨师,看看厨房里是否已经有其他人知道如何做饭(厨房是网络服务器)?如果有人知道如何做饭Boomyhoor
,那么他/她会为您服务。
Now, consider that you go another time, and this time ask for Graboori
. Chef already knows (from a dictionary) that Graboori
is just another name for Pizza. Because he knows how to server pizza, he simply serves that.
现在,考虑您再去一次,这次要求Graboori
. Chef 已经知道(从字典中)这Graboori
只是 Pizza 的另一个名字。因为他知道如何提供比萨饼,他只是简单地提供。
When you add a MIME type to a web server, you simply map a request extension to a file type.
将 MIME 类型添加到 Web 服务器时,只需将请求扩展名映射到文件类型。
回答by milad raeisi
you must add
你必须添加
<staticContent>
<mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent >
to your Web.config
到您的 Web.config
sample :
样本 :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent >
<rewrite>
<rules>
<rule name="WordPress: http://YourSite.com" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<authentication mode="None" />
</system.web>
</configuration>