9

I upgraded an existing MVC4/WebAPI1 project to MVC5/WebAPI2 in Visual Studio 2012 as described here. The site worked as expected. I then followed the directions for attribute based routing found here - except I keep getting a 404 for the controllers. My steps were:

  • Add config.MapHttpAttributeRoutes(); in WebApiConfig.Register
  • Add config.EnsureInitialized(); in WebApiConfig.Register
  • Add AttributeRouting (ASP.NET WebAPI) from NuGet
  • Add the Route attribute on my test controller

I see that the test route is getting registered when I put a break after config.EnsureInitialized(). However, trying to hit that route gives me a 404.

If there any way out of the box to inspect the request and see how the routing table is being matched?

Jamie Dixon
  • 4,204
  • 4
  • 25
  • 47
  • 1
    Which package are you referring to when you say `Add AttributeRouting (ASP.NET WebAPI) from NuGet`...attribute routing is built-into Web API and you need not be installing any other extra package to have it working...are you by chance installing Tim McCall's attribute routing package instead? – Kiran Dec 23 '13 at 19:23
  • Yes, it was. I reverted the changes (thank goodness for source control) – Jamie Dixon Dec 24 '13 at 10:12

2 Answers2

14

I had the almost the same issues. And cannot find any working solution. The Route debugger is really doesn't work with Web API 2. Finally, I've found a working way to debug Web API 2 including Route Attributes.

Microsoft.AspNet.WebApi.HelpPage

Нope this helps someone save a few hours of debuging.

dmytrops
  • 496
  • 7
  • 11
  • 1
    How did that help? Can you explain what you did with that link? I tried installing the package mentioned in the link but Route Debugger still doesn't work. – stone Jul 03 '14 at 06:29
  • 5
    I think that what he meant was that by installing the HelpPage package you would be able to navigate to /help and see all your WebApi routes, URL parameters and/or body parameters from which you could be able to pinpoint problems – Dominic St-Pierre Sep 28 '14 at 12:26
  • Simply installing it helped me - but I think only because it installed several dependency packages that I must have been missing - all in the Microsoft.AspNet.WebApi namespace. I think it's a case of mysterious-missing-dependency syndrome. Seems to happen a lot to me lately. :-\ – egandalf Jan 11 '16 at 23:54
  • 1
    hmmmm.. installing Help page didn't work for me - but, it does make some very nice help pages and *it does properly enumerate my routes* .. but I still get 404 errors. FWIW: [Here's info on how to use help page](http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages) – bkwdesign Feb 17 '16 at 05:56
0

You can use Route Debugger to inspect all Routes. There's an official post from MSDN that covers this:

Fals
  • 6,813
  • 4
  • 23
  • 43