I have a problem
My route have an extra paramater after hierarchical category.
/2009/World/Asia/08/12/bla-bla-bla
asp.net mvc does not support this because my routing should be
{year}/{*category}/{month}/{day}/{name}
i tried use constraint like
year = @"(\d{4})",category = @"((.+)/)+", month = @"(\d{2})", day = @"(\d{2})"
but i cannot find any solution.
Is there any comment?
Thank you
If I understood well, you want to limit and put some constraints on values can pass as routing sections, You can do it with Route Constraint. Plaese read Creating a Route Constraint (C#) and you will find how that is possible. You can do it same as below:
The regular expression \d+ matches one or more integers. This constraint causes the Product route to match the following URLs:
But not the following URLs:
Additionally you could write your custom route constraint, Please read Creating a Custom Route Constraint (C#) and see below sample I just copied from This post by Guy Burstein that I think you find it useful:
As Guy said: In order to implement a Custom Route Constraint, you should create a class that inherits from IRouteConstraint, and implement the Match method.
Hope this help.
I'm pretty sure that the route handler tokenizes on the slash character so you won't be able to have a category that includes a slash -- though escaping it might work, not sure about that. You might want to format your URL as:
This should translate the category as "World Asia".
If that doesn't work then perhaps you need another route that matches on subcategory as well.
Add another rule to your routing with the name parameter.