Question

I have built a custom HttpHandler that issues a status page whenever a specific resource is requested by the load balancer.

Some more background: It can't be a controller as I need to be able to share it with other assemblies and the company coding policy is not to allow controllers from other assemblies. Also, I cannot use a delegating handler as I don't want to affect the pipeline by adding a global message handler.

So I have the following in the web.config:

<system.web>
...
    <httpHandlers>
        <!-- Status Page-->
        <add verb="GET" path="*" type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />
    </httpHandlers>
...
</system.web>
<system.webServer>
...
    <handlers>
        <clear/>
        <add name="StatusPageHandler" path="*" verb="GET" type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />
    </handlers>
...
</system.webServer>

When I try to access the handler (http://foo.bar/status) it fails with a 404. If I remove the resource mapping for the default controller (from global.asax) then it works. i.e. without the following statement in global.asax it works:

routes.MapRoute("Default", "{controller}", null, null);

I stumbled upon a url for which it does work: http://foo.bar/status/XXX, but that is hardly ideal - we don't want to have to extend the url in that "ugly" way.

How do I get it to work?

Was it helpful?

Solution

One way to get it to work. Change Web.Config like so.

<add name="StatusPageHandler" path="status" verb="GET" 
     type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />

Add the line in Global.asax (RouteConfig.cs?) to ignore this route. Make sure you add this line before routes.MapRoute.

routes.IgnoreRoute("status");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top