LESS 文件无法加载 (404)
我使用的是 IIS 7.5,但无法加载 less 文件,因为它给出了 404 错误。
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Less Tutorial</title>
<link rel="stylesheet/less" href="style.less" />
<script src="less-1.0.41.min.js"></script>
</head>
<body>
<div id="container">
<a href="#">My Anchor</a>
</div>
</body>
</html>
更少:
@primary_color: green;
#container {
width: 200px;
height: 200px;
background: @primary_color;
}
I'm using IIS 7.5 and I'm unable to load the less file because it gives a 404 error.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Less Tutorial</title>
<link rel="stylesheet/less" href="style.less" />
<script src="less-1.0.41.min.js"></script>
</head>
<body>
<div id="container">
<a href="#">My Anchor</a>
</div>
</body>
</html>
LESS:
@primary_color: green;
#container {
width: 200px;
height: 200px;
background: @primary_color;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个很好的视频教程,应该可以帮助您入门 -> http: //net.tutsplus.com/tutorials/html-css-techniques/quick-tip-you-need-to-check-out-less-js/
编辑:不是真正的修复,而是一个小提示。打开样式标签或链接到链接标签中的样式表时,始终添加
type="text/css"
。Here is a good video tutorial that should get you started -> http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-you-need-to-check-out-less-js/
EDIT: not really the fix but a small tip. always add
type="text/css"
when opening style tags or linking to a stylesheet in the link tag.使用 Asp.Net 时,您可以在 web.config 中添加 mime 类型:
When using Asp.Net you can add the mime type in your web.config:
使用 webmatrix 时,转到“Documents\IISExpress\config”,打开“applicationhost.config”并添加行 mimeMap fileExtension=".less" mimeType="text/css"在“staticContent”部分下。希望这有帮助。
When using webmatrix go to "Documents\IISExpress\config" open "applicationhost.config" and add the line mimeMap fileExtension=".less" mimeType="text/css" under the section "staticContent". Hope this helps.
在我的 MVC 5 应用程序中,我尝试了许多这些方法,但无法解决问题。最终,我安装了 VS 2013 的 Web Essentials 并利用了内置的 LESS 编译器。每次保存 LESS 文件时,它都会生成相应的 CSS。在我的布局中,我只需指向 CSS 文件并解决我的问题。
In my MVC 5 application, I tried many of these approaches and couldn't resolve the problem. Ultimately, I installed Web Essentials for VS 2013 and took advantage of the built-in LESS compiler. Every time you save your LESS file, it will generate the corresponding CSS. In my layout, I simply point to the CSS file and worked around my trouble.
我现在多次遇到这个错误,尽管添加了 mime 类型,但我一遍又一遍地遇到相同的错误。
然后我发现添加 mime 类型只能修复 406 错误代码,而不是 404。我认为这与权限有关。
因此尝试以管理员身份打开该文件(例如
notepad.exe
->以管理员身份运行
)并用其自身覆盖该文件。这对我有用。I faced this error multiple times now and despite adding a mime type i got the same error over and over again.
Then i discovered that adding a mime type just fixes the 406 error code, not 404. It has something to do with privileges i think.
So tryed to open the file as Administator (like
notepad.exe
->run as Administrator
) and overwrite the file with itself. This worked for me.