MVC3 和正则表达式路由参数
我们正在转向 MVC3,并且我们已经有了一个复杂的 url 重定向/重写方案。
我们有 [我认为] 复杂的 url,需要分解为其组件值。
例如,网址 http://web-current/billet-grilles/10a50164A.aspx,需要删除 10 和 50164 并将其作为参数传递。
以下是我们现有的正则表达式:
([^/]+)/10[A|a]([0-9]+)[A|a]{0,1}.aspx[\?]*([^/]*)
我已经尝试过,但遇到了问题:
RouteTable.Routes.MapRoute("Department", "{silo}/10[A|a}{departmentId}[A|a]{0,1}.aspx", new {controller = "Department", action = "Index"}, new {silo = ".*", departmentId = "[0-9]+" })
您有什么建议吗?
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]{0,1}.aspx", new {controller = "Department", action = "Index"}, new {silo = ".*", departmentId = "[0-9]+" })
Do you have any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用了 http: //iridescent.no/post/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx。
这非常有效,谢谢
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