So I've been trying to map an http module to a sub-path of an MVC3 site. It should be pretty simple as I understand it, but it has not been working. The module is setup like so:
<handlers>
<add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</handlers>
A matching section is also there for iis6 so I can run it under webdev.webserver. However testing both deploying to my local iis7 (under Win7) and with webdev.webserver, only /api actually calls the handler. If I call /api/{anything} it just returns a 404.
I'm sure I'm just "doing it wrong (tm)" but any help would be appreciated.
Note: I've also tried a couple other configurations including using a tag and creating a /api folder and adding a web.config to that folder with a full wildcard.
The
URLRoutingModule-4.0
is a catch all handler listed before your nancy handler. It will thus come into play before your handler is ever hit. You can remove the handlers add yours and add them back in like so:You can see the handler order in IIS7 under
Handler Mappings
selectView Ordered List
and it will list the order in which it loads the handlers top (first) to bottom (last).You might need a second
Web.config
in your/api
folderSimilarly, this is what I usually do for "/static" content on websites. I have not found out how to circumvent the need for the seconds web.config.
EDIT
I had a hard time figuring this out when i had to as well and it seems my memory hasnt served me well. I dont specify a
path/*
handler anywhere instead I have this:(only specifying simple wildcards/fully qualified paths to go around UrlRouting)
Then in my
/Content/web.config
file I set the following:My handler list for
/Content/
looks like this now:Which is about as sure as I can be anything in
/Content/
will be served through StaticFileModule. The trick here seems to be specifying:inheritInChildApplications="false"
.Simple. Just put the path, no wildcard.
This will match:
Seems the UrlRoutingModule-4.0 is more trouble than it is worth. Instead I've just told MVC3 to ignore the routes. Not a perfect solution but until I have something that works better I'll have to stick with this in
RegisterRoutes
: