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