Jamie Treworgy
Jamie Treworgy

Reputation: 24344

Custom HttpHandler never running

Forgive me if this is basic. I've never made one before and can't seem to figure out why it's not working. I wrote a little handler to do some parsing on CSS files. I added this:

    <system.web>
        <httpHandlers>
          <remove verb="*" path="*.css"/>
          <add verb="*" path="*.css"
type="MyNameSpace.CssRelativePathHandler,CssRelativePathHandler" />
        </httpHandlers>
    </system.web>

Nothing ever happens. CSS files get parsed normally. No errors, nothing, the code never runs. What am I missing? Shouldn't this cause the handler to be used when *.css files are served? (I added the "remove" later, since I thought perhaps I needed to do that to override a built-in hander, again, no difference either way).

This is IIS 6. I added the IIS 7 code anyway (after searching for answers) but makes no difference.

     <system.webServer>
        <handlers>
          <add name="CssHandler" verb="*" path="*.css"
type="MyNameSpace.CssRelativePathHandler,CssRelativePathHandler" />
        </handlers>
      </system.webServer>

Upvotes: 2

Views: 533

Answers (3)

Dave Transom
Dave Transom

Reputation: 4185

It sounds like you need to configure IIS to enable ASP.NET to execute the .css extension.

Phil Haack has a walkthrough on doing that (just replace .mvc with .css under the heading "Mapping .mvc to ASP.NET"): http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

Or you can set up a wildcard mapping in IIS 6: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

I'd recommend going with the first method as doing the wildcard approach will send all requests to ASP.NET - so it has a more overhead.

PS: Further down Phil's post, he also lists "IIS6 Extension-less URL" and also covers the wildcard mapping method.

Upvotes: 0

Samuel Neff
Samuel Neff

Reputation: 74939

For IIS 6 you need to have to tell it to send *.css files to ASP.NET.

  1. Launch IIS Manager
  2. Right-click on Default Web Site
  3. Click on the Home Directory tab
  4. Under Application Settings click on Configuration...

Add a new association for .css and map it to .NET executable:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

Upvotes: 0

SLaks
SLaks

Reputation: 887867

You need to configure IIS6 to send requests for .css files to ASP.Net.

Had you been using IIS7, your <system.webServer> element would have done that for you, but IIS6 predates this.

Upvotes: 1

Related Questions