Skip navigation

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.

About these ads

7 Comments

  1. Hi Troy,
    Thanks for starting this project! I seem to have a lot of troubles with routing so this is sorely needed. However, it’s not working for me. When I attempt to debug a route, it simply displays “000″. Screenshot
    https://dl.dropbox.com/u/420082/WebApiRoutingError.png

    This is with the latest version of WebAPI Route Debugger (1.0.0.0) and all my other NuGet packages are up to date as well.

    Is there any way I can help you debug this – sending my web.config, NuGet package list, logs, anything?

    • Hi John,

      The codes of how you set up your route will be useful.

      Regards,
      Troy

  2. Troy,

    This was working great, initially. Now though, although I can load the /rd page whenever I try to test valid route I get this exception:

    Exception information:
    Exception type: NullReferenceException
    Exception message: Object reference not set to an instance of an object.
    at System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(IAsyncResult result)
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Any ideas? I tried uninstall/reinstalling the nuget package and no go. Same error.

    • Hi James,

      Thanks for using my tool and sorry for the exception. I’ll take some time to talk a look at it today.

      Regards,
      Troy

  3. I’ve installed your nuget package, but it’s not working. I get a “No type was found that matches the controller named ‘rd’.” It would be very helpful if you’d explicitly state what the package is supposed to install/configure, so that we can verify everything is configured correctly. For instance, I expected to see some Global.asax changes for routing to include your Area, but I found none.
    Any help will be greatly appreciated.

    • Hi Tim,

      The route debugger relies on MVC Area to be functional. It adds source codes under Areas and which will be picked up by Area registration. Did you remove all areas from you project?

      Regards,
      Troy

        • Tim
        • Posted April 15, 2013 at 11:11 am
        • Permalink

        It’s a highly customized (stripped-down) web api project. I got most of your package working by adding “AreaRegistration.RegisterAllAreas();” into Global.asax.cs on AppStart. I also had to add jquery, knockout, and bootstrap stuff directly to your area for styling. Any pure webapi project will not have any UX whatsoever, so you shouldn’t expect those items to be present. You should also add a config key to easily turn all of the functionality on or off.

        Other than that, it’s great! Thank you for your work.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: