Skip navigation

Monthly Archives: February 2013

Source codes will be put on codeplex.com soon….

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:

  1. http://stackoverflow.com/questions/13876816/web-api-routing
  2. http://stackoverflow.com/questions/13869541/why-is-my-message-handler-running-even-when-it-is-not-defined-in-webapi
  3. http://stackoverflow.com/questions/14058228/asp-net-web-api-no-action-was-found-on-the-controller
  4. http://stackoverflow.com/questions/13982896/versioning-web-api-actions-in-asp-net-mvc-4/14059654#14059654

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.

User Instruction

Installation

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:

Capture

Put the URL you want to test and click send.

Capture

The results is composed of 5 parts:

  1. The HTTP status code. In above example you see a 200, but if you hit a non-exist resource, you will see a 404.
  2. Route Data: what’s the route template and data parsed from URL.
  3. Route selecting: among all the routes, which one is chosen.
  4. Controller selecting: among all controllers found in assemblies, which one is selected.
  5. 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:

GET http://localhost:57887/api/value

Capture

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.

Advertisements