Hidalgo
Hidalgo

Reputation: 941

Processing Less file on client in ASP.NET project

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?

Upvotes: 3

Views: 1717

Answers (2)

JanR
JanR

Reputation: 6132

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> 

Upvotes: 5

J. Polfer
J. Polfer

Reputation: 12481

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.

Upvotes: 1

Related Questions