routes.MapRoute(
name: "Without Controller",
url: "{id}",
defaults: new { controller = "myControler", action = "Index", id = UrlParameter.Optional },
constraints: new { id = new NotEqual("Home")});
定制路线:
public class NotEqual : IRouteConstraint
{
private readonly string _match = String.Empty;
public NotEqual(string match)
{
_match = match;
}
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return String.Compare(values[parameterName].ToString(), _match, System.StringComparison.OrdinalIgnoreCase) != 0;
}
}
问:我需要筛选既“首页“和”登录“ids.How can I do it?任何帮助将不胜感激。
constraints: new { id = new NotEqual("Home")});//I need to give "Login" also ?
为什么不通过一个CSV和内部处理它?即NotEquals(“Home,Login”)'。 – webnoob 2014-11-08 21:14:48