Why isn't my IHttpHandler being called?
Asked Answered
T

2

27

I'm trying to get a custom handler to work for a specific URL (or set of URLs) in ASP.NET 3.5.

The handler doesn't actually do anything significant yet - it just logs the request. I can post the code if anyone things it's relevant, but I really don't think it's being called at all. (In particular, for normal exceptions I get a custom error page and logging... here I'm just getting the vanilla IIS 404.)

Here's the relevant bit of the web.config file:

<system.web>
  <httpHandlers>
    <add verb="GET,POST" path="*.robot" validate="false" 
         type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
  </httpHandlers>
</system.web>

(Obviously there's other stuff in that section too, but I don't think it's relevant.)

Locally, running under the dev server, it works fine. On my real box, I always get a 404. Everything under the web site directory itself is the same (replicated via svn). That includes the bin directory containing CSharpInDepth.dll, which I've verified contains CSharpInDepth.Wave.RobotHandler.

I try to fetch http://csharpindepth.com/foo.robot and just get a 404.

I've tried with and without the assembly name, specific URLs or wildcarded ones... nothing's working.

I'm sure I've just missed some simple flag somewhere in the IIS configuration, but I'm blowed if I can find it...

EDIT: It's IIS version 6. Attempting to add *.robot to the ISAPI filter now...

Tel answered 4/9, 2009 at 19:57 Comment(0)
M
33

Well if the hosting box is IIS7 in integrated pipeline you need to add it into the other bit of the config:

<system.webmodules>
  ....
  <modules>
    <add name="RobotHandler" type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
  </modules>
  ....
</system.webmodules>

If it's IIS6 then you'll need to map *.robots to the ASP.NET ISAPI DLL.

(For the non-Skeets you do this as follows)

  1. Open up IIS admin.
  2. Right click on the Web site you want to configure and select Properties form the context menu. This will display the Web Site Properties dialog.
  3. Select the Home Directory tab and click the Configuration button. This will display the Application Configuration dialog box.
  4. Click Add.
  5. Select the aspnet_isapi.dll from the .NET framework directory, the extension you want mapped and either All Verbs, or just the ones you want to map.
  6. Click ok.
Mopup answered 4/9, 2009 at 20:0 Comment(9)
Bah - after experimenting, I've just written that set of instructions up in the question. Will edit them out again :)Tel
Aargh... it worked for my foo.robot example, but now I need to serve just "jsonrpc" (full URL - csharpindepth.com/Wave/_wave/robot/jsonrpc). Obviously that doesn't have an "extension" per se... any clues?Tel
You don't have a hope. Directories are served by IIS, not ASP.NET. You could fake it by creating it, and putting a default.aspx file in there, or of course ISAPI rewriters which map it to a real aspx, at which point ASP.NET will kick inMopup
@blowdart: So how does ASP.NET MVC do its mappings? Does that use a rewriter? I'll try the default.aspx file...Tel
@blowdart: Bah. It serves a redirect. That'll be no good. Hmm. Might whinge at the Wave team and ask them to reconsider their URL choice :)Tel
Hmm ASP.NET MVC maps everything (on IIS6) if you want it to work right. Mind you not sure about how it copes with virtual directories - there's a virtual path provider which might do it, support.microsoft.com/kb/910441Mopup
@blowdart: For the moment, I've changed my AppEngine Wave Robot proxy to add ".robot" onto the end if the path ends with "jsonrpc". Ugly, but it'll do for now :)Tel
@Jon Skeet, I see this is old, but in case you didn't realize this yet, you can use an IRouteHandler implementation to resolve the IHttpHandler programatically (in either MVC or WebForms). (This requires including the UrlRoutingModule in your web.config)Calisaya
Obviously this is ancient history now, but just wanted to add - I ran into this problem and fixed it by adding the modules above into the system.webServer node, rather than system.webmodules - very strange!Loveridge
G
9

Jon,

You'll have to configure the IIS script mappings to pass *.robot to aspnet_isapi.dll.

Giorgione answered 4/9, 2009 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.