Routing revisited

It turned out to be a lot easier to work around not being able to override the route parsing method then I had thought it would be last night. Though when they allow me to override that method I will be changing over.

By setting up the following routes I was able to get almost the effect that I was looking for:

RouteTable.Routes.Add(new Route
{
    Url = "Example/[id]/[action]",
    Defaults = new { Controller = "Example" },
    RouteHandler = typeof(MvcRouteHandler)
});

RouteTable.Routes.Add(new Route
{
    Url = "Example/[Category1]/[id]/[action]",
    Defaults = new { Controller = "Example" },
    RouteHandler = typeof(MvcRouteHandler)
});

RouteTable.Routes.Add(new Route
{
    Url = "Example/[Category1]/[Category2]/[id]/[action]",
    Defaults = new { Controller = "Example" },
    RouteHandler = typeof(MvcRouteHandler)
});

Though the execute action just takes the id in

[ControllerAction]
public void Execute(string id)

If I find that I actually need access to the Categories found in the path, I can access them using RouteData.Values. It also helps that I had decided that the examples should have a unique ID, that will be a lot like the friendly Urls used in Subtext. That way the directories are there more for aesthetics then utility. Though when the ability to override the route parsing, I will probably be changing it to this if possible later:

[ControllerAction]
public void Execute(string id, string[] categories)

So now that I have the site navigation working the way that I want it, with the exception of a helper method for writing out the longer category listings, its time to work on the maintenance parts of the site.

And so far it seems that this will be a better fit then WebForms was for the last few reworks of the site, since I can make the UserControls containing the examples completely isolated, including having the runat server form in the control. The only one I liked better was the JSON based one, using ASP.Net AJAX Extensions, which would have gone live if AdSense worked with AJAX/JSON sites.

Overall the more I use it the more I like the feel of the framework. Especially now that I realized which of these  I wanted to selected when using a master page.
image

 

And so far the best part of the framework is that I don’t have to ignore features to not see this dialog after refreshing the page I just navigated to.

image 

Technorati Tags: