ASP.NET Web API Route Debugger
Over the time, I found around one third of the user questions of Web API is about routing. Such as:
There is no easy way to figure out how the route were decided and eventually everything retrogress into “guessing”.
I was inspired by Haack’s ASP.NET Route Debugger, and decided to build a route debugger for ASP.NET Web API. The tool should visualize the routing mechanism and exposing as much information as possible to help user design their routes easily.
You can install Web API route debugger from NuGet
PM> Install-Package WebApiRouteDebugger
If you don’t want to find the package in NuGet Packages Dialog, please make sure you include the Prerelease packages. The package is still in alpha stage.
Route Simulate Page
The package will create an area, under which all components and views are installed. Run your site, navigate to http://<SiteUrl>/rd (if you’re using IIS Express, it may look like http://localhost:52135/rd).
You will see this page:
Put the URL you want to test and click send.
The results is composed of 5 parts:
- The HTTP status code. In above example you see a 200, but if you hit a non-exist resource, you will see a 404.
- Route Data: what’s the route template and data parsed from URL.
- Route selecting: among all the routes, which one is chosen.
- Controller selecting: among all controllers found in assemblies, which one is selected.
- Action selecting: for the action on the selected controller, which action is selected and why. The chart visualize the decision making process.
Here’s another example:
Since there is no “Value” controller in the system it hits a 404. You can see the “Controller” value in route data is “Value”. The route is selected. However there is no controller mapped.