anaisbetts / SassAndCoffee

SassAndCoffee adds support in ASP.NET MVC to (you guessed it!) Sass/SCSS and CoffeeScript
http://blog.paulbetts.org/index.php/2011/06/06/new-release-sassandcoffee-0-9-now-not-glacially-slow/
Microsoft Public License
199 stars 37 forks source link

PipelineHandler should NOT send out 404's #58

Closed nicholashead closed 3 months ago

nicholashead commented 12 years ago

Specifically this code:

if (result == null) {
    response.StatusCode = (int)HttpStatusCode.NotFound;
    return;
}

It's a little arrogant to think that the PipelineHandler is the only IHttpHandler that could possibly handle that filetype.

This leads to fun bugs, such as StackOverflow's MiniProfiler no longer working, because it requests a file such as:

/mini-profiler-resources/includes.css?v=sdjkfsdf

Which PipelineHandler (when trying to handle .css) says "oh, it doesn't exist" and sends a 404, killing the response instantly.

kogir commented 12 years ago

HttpHandlers don't chain. Once the request gets set to the PipelineHander, there is nowhere else it can go. Sending 200 OK with an empty body and telling IIS to cache it probably isn't the behavior you want either.

What I suspect you'd prefer is for SassAndCoffee to play nice with MVC routes. The PathBasedHandlerRemapper doesn't. Patches to enable this are welcome.

As a workaround in the meantime, you can remove the module registration and add a custom route that sends .css files to the correct PipelineHander as a last resort, after all other routes fail to match.

nicholashead commented 12 years ago

Thanks for the clarification. Not sure how to make an IHttpHandler aware of MVC routes, otherwise I'd send in a patch.

But in general, it seems like telling .NET you're handling all "not real" .css requests is a bad practice. Maybe there should be a better solution for that?

kogir commented 12 years ago

Well, yes and no. IIS 6 and 7+ have different capabilities. ASP.Net 2 and 4 have different capabilities. System.Net.Routing and full on MVC2/3/4 have different capabilities. The current hack listens to all incoming requests and takes control of all .css and .js requests at the earliest stage. It's hardly ideal, but in many cases it works. You found one of the places it falls apart.

Luckily - while the default configuration doesn't work for you, the pieces are there to solve your problem. You should be able to add a route that maps to a controller that does the same work that PipelineHander does.

Unfortunately I'm slammed at the moment with other work and won't have time to fix some of these glaring bugs for months :/