LESS file does not load (404)

2019-01-31 05:30发布

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

5条回答
女痞
2楼-- · 2019-01-31 05:56

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.

查看更多
乱世女痞
3楼-- · 2019-01-31 06:02

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.

查看更多
唯我独甜
4楼-- · 2019-01-31 06:02

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 try to open the file as Administator (like notepad.exe -> run as Administrator) and overwrite the file with itself. This worked for me.

查看更多
虎瘦雄心在
5楼-- · 2019-01-31 06:09

When using Asp.Net you can add the mime type in your web.config:

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".less" mimeType="text/css" />
  </staticContent >
</system.webServer>
查看更多
贪生不怕死
6楼-- · 2019-01-31 06:12

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.

查看更多
登录 后发表回答