c# - How to know when Web API Routing Engine Doesn't Find a Matching Service? -


i'd log requests web api application results in 404 (which means routing engine couldn't find matching service).

how possible?

for example, if have below mapping:

config.routes.maphttproute(                 name: "defaultapi",                 routetemplate: "api/{controller}/{id}",                 defaults: new                     {                         id = routeparameter.optional                     }                 ); 

then calling below return 404:

api_rootnotvalid/controllername 

i want capture such requests , log them.

i've created class inheriting delegatinghandler when routing engine succeeds finding service goes delegatinghandler.

so think there should else can help?

i think tricky thing do...some info might need consider:

  • route matching happens @ different stages when compared webhost(iis) , selfhost. web api stack diagram reference.

    • webhost - happens before message handlers run. delegating handler wouldn't executed if route doesn't match.
    • selfhost - happens after message handlers run , @ httproutingdispatcher. in case delegating handler executed , check response's status code, error prone due next point.
  • a 404 response due route not being matched or if route matched application level code has responded 404 (ex: api/products/10 can return 404 if product id 10 not found). here task find whether route matching generated 404 or application level code.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -