3

We have a website that makes use of .less files (the pre-compiler dotless has been installed using nuget), however the .less files are not handled as css files.

When trying to view the website in firefox, the console gives use the following error: The stylesheet http:// website/css/init.less was not loaded because its MIME type, "application/octet-stream", is not "text/css".

Our dotless file is trying to import more files:

@import "imports";
..

But even replacing this text with css code, the styles are still not applied. But if I go to that file in Visual Studio, it is displaying all the css from the files that are imported.

Lex
  • 879
  • 3
  • 16
  • 27

1 Answers1

2

If you're using the dotLess handler to process and serve your .less files on the fly (which is fine for debugging, but you might want to consider pre-compiling for release), you need to ensure that you also send them down with the correct mimetype.

You can do this either at the server level in IIS Admin (if you're likely to using this for multiple sites on the machine), or at the local site level via the web.config - note that you can't do both, IIS will complain that there are multiple entries for the file extension.

To do this in the web.config, within the <configuration><system.webServer> element add the following elements:

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

Obviously, if you've already got some mimemap entries, just add the mimemap there.

This will ensure that IIS claims that the .less files served from the handler as CSS rather than the default application/octect-stream.

If that's still not serving them as processed, there are a couple of other things you'll need to check:

  1. Ensure that the handler is correctly registered in both the <system.webserver><handlers> and <system.web><httpHandlers> sections (depending on the version of IIS you're using:
    <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
    and
    <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
  2. Ensure that IIS is configured to send all requests through the ASP.NET handlers configured in step 1. By default, .less files are probably being considered "static files" and will only be handled by the StaticFileModule.
    enter image description here
Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • We have tried the config file setting, however its still shows the content of the less files and not processing them correctly. – Lex Dec 18 '14 at 10:55
  • Are you sure the dotLess handler is correctly registered then? – Zhaph - Ben Duguid Dec 18 '14 at 10:56
  • I think it is set up correctly, but I'm not sure now. I installed dotless via nuget, added the required bits to the web.config file. And according to the dotless website that is all you have to do. We are running this solution as a website, rather than a webapp, so would that make a difference? – Lex Dec 18 '14 at 11:02
  • Installing via NuGet (`Install-Package dotLess`) should set everything in the web.config correctly for you: The 2 handlers I've just added to my answer as well as the configSection and the default settings. What version of IIS are you running on? – Zhaph - Ben Duguid Dec 18 '14 at 11:15
  • 1
    the IIS option did work for us, so we have decided to go ahead and use that as our solution. – Lex Dec 18 '14 at 14:07