MVC3 and regex route parameters
We are moving to MVC3 and we already have a complex url redirect/rewrite scheme in place.
We have [what I consider to be] complex urls that need to be decomposed to their component values.
For instance, the url http://web-current/billet-grilles/10a50164A.aspx, needs to have the 10 and the 50164 removed and passed as parameters.
The following is our existing regex:
([^/]+)/10[A|a]([0-9]+)[A|a]{0,1}.aspx[\?]*([^/]*)
I have tried this, but I run into issues:
RouteTable.Routes.MapRoute("Department", "{silo}/10[A|a}{departmentId}[A|a]开发者_StackOverflow{0,1}.aspx", new {controller = "Department", action = "Index"}, new {silo = ".*", departmentId = "[0-9]+" })
Do you have any advice?
I ended up using a new route object from http://iridescence.no/post/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx.
This works perfectly, thanks
精彩评论