views:

96

answers:

2

If say I have a route that is defined like this: "{books}/{*all}", then any URL that have a root folder defined will match it (i.e. http://mysite.com/greekbooks/somethingirrelavant.htm).

But what if I wanted to go further, and would like to present a custom handler for greekbooks published in 1982 (i.e. the url http://mysite.com/greekbooks/1982/anythinghere). I would really not like to put this logic into my first route handler, but to present a second one to deals with serving pages when this url is matched.

The problem is that "{books}/{*all}" will eat "{books}/1982/{*all}" also.

Basically how do you define more than one route handler when dealing with '*' ( all ) match? Is it possible at all?

A: 

Yes it's possible. You would put your additional

{book}/{year}/{*all}

catch first. I would go one step further and suggest that you add a constraint to the {book}/{year}/{*all} route so that it is only numeric.

Chance
A: 

You can do this by controlling the order that the routes are defined because a URL is evaluated against routes in the order that they are added to the Routes collection.

Here are the rules for how Routes are processed...

  1. The route patterns that you have defined or the default route patterns, if any, that are included in your project type.
  2. The order in which you added them to the Routes collection.
  3. Any default values that you have provided for a route.
  4. Any constraints that you have provided for a route.
  5. Whether you have defined routing to handle requests that match a physical file.

ASP.NET Routing

CptSkippy