views:

46

answers:

3

Hi,

In an ASP.NET application, I need to do some changes on every CSS file sent.

So I created an HttpHandler (inside the app itself), added:

<add verb="*" path="*.css" type="MyWebsite.CssTestHandler,MyWebsite"/>

to Web.config in system.web/httpHandlers and modified the handler like this:

public void ProcessRequest(HttpContext context)
{
    context.Response.Clear();
    context.Response.Write("Hello World");
    context.Response.End();
}

But CSS files are still just like they were before, so the handler is just ignored.

What I'm doing wrong?

+2  A: 

You need to setup a wildcard map in IIS, see the following link:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

This will cause the request for the CSS file to be served by ASP.NET rather than just IIS.

If the application serves very high traffic, consider setting this mapping for .css files only, or even better change the CSS data in the page rather than changing the file.

amarsuperstar
+1  A: 

The App ignores your CSS files because IIS ignores CSS files.

It's not mapped to an executable in IIS. alt text

Try adding the .css extension and map it to the .NET dll.

Ed B
+1  A: 

Check this page for instructions on all 3 cases of IIS version (6, 7 Classic pipeline and 7 Integrated pipeline): http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

According to it, in case of Integrated pipeline, you need to add the following config parameter:

runAllManagedModulesForAllRequests="True"
Artem K.