My Route :
routes.MapRoute(
name: "Without Controller",
url: "{id}",
defaults: new { controller = "myControler", action = "Index", id = UrlParameter.Optional },
constraints: new { id = new NotEqual("Home")});
Custom Route :
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;
}
}
Question : I need to filter both "Home" and "Login" ids.How can I do it ? Any help would be highly appreciated.
constraints: new { id = new NotEqual("Home")});//I need to give "Login" also ?
NotEquals("Home,Login").