Constraining Routes
1.Constraining a Route Using a Regular Expression
The first technique we will work at this constraining a route using regular expressions.lising contains an example:
public static void RegisterRoutes(RouteCollection routes) {
routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "^H.*"},
new[] { "URLsAndRoutes.Controllers"});
}
We define constraints by passing them as a parameter to the MapRoute method.Like default values,constrains are expressed as an anonymous type,where the properties of the type correspond to the names of segment variables we want to constrain.
In this example,we have used a constraint with a regular expression that matches URLs only whe... (查看原文)
2 有用 黑猿大叔 2014-12-25 13:46:17
适合从第一页开始顺序往下读,作者会精心的引导读者一步一步建立起整个知识框架。
0 有用 取个啥名儿呢 2013-08-17 18:50:07
介绍MVC不错的书