Dotless File Yields 404 Error in IIS
Asked Answered
S

2

11

I've been successfully using .less files in my dev Cassini server (with dotless) for a few weeks but when I publish to my local IIS server they yield 404 errors. Attaching my debugger to IIS yields no exceptions. I've restarted my IIS app pool and server as well.

Any ideas?

Succuss answered 17/5, 2011 at 0:53 Comment(0)
N
31

Looks like you're missing a mime type on IIS.

For IIS7 add the following to your web.config:

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

For IIS6 you can do (presuming you have administrator RDP access):

cscript adsutil.vbs set W3SVC/1/Root/MimeMap ".less, text/css"

Where /1/ is the IIS number of the site.

Nematic answered 17/5, 2011 at 1:11 Comment(6)
you nailed it, thanks man! Stackoverflow comes to the rescue again.Succuss
Much love. I love instant solutions.Rossini
For IIS6 I had to use cscript c:/Inetpub/AdminScripts/adsutil.vbs set W3SVC/1/Root/MimeMap ".less, text/css"Thomas
I'm just not getting results with this fix. It's driving me nuts. Everything works with cassini but when I publish to IIS 7 it doesn't work.Bachelor
@Bachelor - you might also consider setting the mimetype using appcmd - technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx - I used both the web.config webServer node addition and appcmd.Tania
Thanks Kurt. Kev's answer fixed the solution, but I like your addition as well.Bachelor
P
8

Just adding (quite late, I realize) my two bits to this discussion.

I just ran into the same symptoms and the previously mentioned fix did not work for me. I did however end up finding another reason for these symptoms and a solution for this.

The 404 response in my case contained the following message in the body of the response:

/* Error Occurred. Consult log or view on local machine. */

This seems to be an indicator that the less file was indeed found and the request was being processed by dotLess (the message can be found in dotLess's source code), but a FileNotFoundException occurred during processing the request.

I tracked down the problem to an @import statement that referred to a .less file that was mysteriously not present on the IIS server, even though it was present under the development server.

It turned out that the build action for this problematic .less file was set to None, not to Content, like all the other .less files in my project.

So the next logical question was why on earth was the Build Action incorrect?

Well, I had added the file as a .css file, then decided to import it into a .less file and thus renamed it to .less (since .css is a subset of .less, but less does not import css files). I repeated the process with a new .css file and found that the problem was reproducable.

It seems that Visual Studio changes the build action from Content to None behind the scenes as an unexpected side-effect of renaming .css to .less. Thus the renamed .less file does not get published to the IIS server.

Polygamist answered 22/8, 2013 at 19:10 Comment(3)
thanks +1, ran into the same problem converting some frameworks to .less, could not figure out for the life of me why it was yielding a 404 until I removed all files from the VS publish..Arsyvarsy
Yup, got me too. Forgot to add a new .less file to the SVN that was meant to be @import-edAbomb
Wow, this was taking me way too long to figure out. My main style sheet was not being compiled into my less build and I had no idea why. Thank you.Agree

© 2022 - 2024 — McMap. All rights reserved.