路线的强度约束?

问题描述:

我打算在URL中使用2char语言,如something.com/EN,/ ES,/ US。有可能为路线添加2char约束?路线的强度约束?

/M

是的,你可以通过routeconstraints来做到这一点。可以将常量传递给global.asax中的Maproutes方法。如果u有可以通过正则表达式来处理约束,其中正则表达式告诉文档ID应该是数字匹配这条路线u能写出像

routes.MapRoute(
       "strict", 
       "{controller}.mvc/{docid}/{action}/{id}", 
       new {docid = "",action = "Index", id = ""}, 
       new { docid = @"\d+"} 

      ); 

。然而 U可以写自己的乌尔班实现IRouteConstraint接口和类的对象可以作为routeconstraint行事乌尔航线

看看这里,看看ü可以如何实现IRouteConstraint

ASP.NET MVC2 Parent Controller Not Redirecting