문제

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?

도움이 되었습니까?

해결책 2

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top