In my last post I described an issue I was encountering with ASP.NET MVC and WCF RIA Services while writing code for Project Thor. The gist of it is that routing was intercepting the calls made to my WCF RIA Services by my Silverlight application and resulting in 404 errors. A quick change to the RegisterRoutes method and voila it worked! Or so I thought…
Since I thought my problem was solved I went on to working on other parts of the ASP.NET MVC side of Project Thor. However, one day, like yesterday, I was running the app and wanted to adjust an admin setting on the Silverlight side, so I typed in the url to the Silverlight page, and I got another 404. What?! That wasn’t supposed to happen. Grrr!
I started going down some pretty nasty rabbit holes on this one. I knew it had something to do with routing, but being new to ASP.NET MVC I wasn’t sure what exactly it could be. At one point I had myself convinced it had do something with local Azure development fabric and integrated pipeline mode on IIS 7.0 running on Windows 7. I wasn’t getting anywhere. I’m not the type of guy that posts my problems and asks for help. I like working through these things on my own (yes, I am a glutton for punishment). However, I needed to get moving so I put the question on Stack Overflow. Within minutes, like 1 minute, I had two responses. The first response was on twitter from John Sheehan. The other response was on Stack Overflow and from none other than Phil Haack. Both responses weren’t a direct answer to my question, but they both pointed me to the ASP.NET Routing Debugger. As the page says:
“This utility displays the route data pulled from the request of the current request in the address bar. So you can type in various URLs in the address bar to see which route matches. At the bottom, it shows a list of all defined routes in your application. This allows you to see which of your routes would match the current URL.”
I downloaded the utility and fired the app up. Here’s what I got for the default page:

Good. Exactly what I expected.
I then tried to navigate to the configuration page that contains the Silverlight application:

Bam! There’s the error! I shouldn’t be getting a match on the first route, the route I want MVC to ignore, the route I told MVC to ignore in my last post. D’oh! If you remember, my RegisterRoutes method looked something like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{Services}/{*pathInfo}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Configuration",
"Configuration",
new { controller = "Configuration", action = "Index" }
);
routes.MapRoute(
"Calendars",
"Calendars/{id}",
new { controller = "Calendar", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Account", action = "Index", id = "" }
);
}
See those curly braces around Services in the first line of the method. Those curly braces that are the MVC convention for replacement. Yeah, um, those shouldn’t be there. I’m not replacing anything. I want to ignore any calls to the actual Services directory. So the updated line looks like this:
routes.IgnoreRoute("Services/{*pathInfo}");
Once I made this change here’s what the testing utility showed me.

Perfect! When I then ran the app without the route debugging utility in place it worked as expected. I’m always amazed and at how so many seemingly complicated problems are solved with one line of code.
So, what’s the upshot of all this? Well, as I mentioned previously, the main goal of Project Thor is to help people, especially me, learn about other technologies they don’t get to work with on a day-in/day-out basis. Today I learned two things about ASP.NET MVC:
- Routing is incredibly simple, ONCE YOU UNDERSTAND IT!!!
- There is a great ASP.NET MVC community out there willing to offer assistance if you need. (Thanks again John Sheehan and Phil Haack!)
In my opinion Project Thor is, once again, accomplishing its goal. Now to finish version one!