views:

7

answers:

0

I am trying to create dynamic routes using .net 4.0 WebForms. Imagine I need mappings like these:

mySite/Canada -> country.aspx
mySite/Canada/Ontario/ -> locality.aspx
mySite/Canada/Ontario/Toronto -> town.aspx
mySite/Canada/population -> country.aspx
mySite/Canada/history -> country.aspx
mySite/Canada/Ontario/weather -> locality.aspx

with countries, localities, towns and custom pages such as population, history and weather being stored in the database. Obviously I cannot use any fixed pattern but I could read all possible paths from database and map them as literal routes. Event though there will be several hundred paths, I am not afraid of bad performance but this approach just feels strange.

Would it be possible to define just one routing rule like {country}/{param1}/{param2}/{param3} and resolve the handler (country.aspx, locality.aspx, town.aspx) on each request by inspecting the parameters against the data in database.

In case I have to use the first approach and the data in database get changed, can I just simply clear the RouteTable.Routes collection and read it again without restarting the application or is it more complicated?

Thank you in advance for all suggestions.