Processing Less file on client in ASP.NET project

烈酒焚心 提交于 2020-01-24 09:53:46

问题


I am trying to change from .css to .less and process this .less on the client using less.js. So I renamed my .css to .less and then added less.js to the project (ASP.NET Web Forms). So the head section looks like this:

<link href="Content/myproject.less" rel="stylesheet/less" type="text/css"/> 
<script src="Scripts/less-1.5.0.min.js"></script>

But when I run the project I get error that file myproject.less is not found. The exact error is:

FileError: 'http://localhost:52714/Content/myproject.less' wasn't found (404)
in myproject.less

The line (in myproject.less) allows me to click on myproject.less which opens the error page:

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. 
If the page is a script, add a handler. If the file should be downloaded, add a 
MIME map.

Most likely causes:
•It is possible that a handler mapping is missing. By default, the static file handler
processes  all content.
•The feature you are trying to use may not be installed.
•The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not 
create a MIME map for content that users should not download, such as .ASPX pages or .config
files.)
•If ASP.NET is not installed.

What is missing in my ASP.NET project?


回答1:


For anyone struggling with the same issue, I know this is an old question however to fix it simply add the following to your web.config (Which will add a mime-type for LESS)

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



回答2:


Double check that the myproject.less file is set to copy to output or into the content directory in the project file?

First, check to see if myproject.less is actually in your build output; if not continue below.

With your project open in Visual Studio, left-click on myproject.less, and examine the properties window. There are two important properties to look for:

  • Build Action - if it is set to Content, it will likely copy over the file in build output and make it available for use in your web application; if not it more than likely won't.
  • Copy to Output Directory - this option overrides the above build action behavior and will ensure that the file will show up in build output and be available for use in your web application.

Try setting "Copy to Output Directory" to true, and see if that fixes it. Learning these techniques are key to ensuring your web application is functioning right.



来源:https://stackoverflow.com/questions/20587765/processing-less-file-on-client-in-asp-net-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!