您可以为此使用自定义约束:
public class MyCons : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
ClassA classA = new Class();
return classA.IsThisTrue();
}
}
然后在您的路线中使用它:
routes.MapRoute(
name: "myRoute",
// your own route
url: "myUrl/{myParam}",
defaults: new { controller = "Some", action = "Index" }
constraints: new { myParam= new MyCons() }
);
// other route
routes.MapRoute(
name: "myOtherRoute",
// your own route
url: "myOtherUrl/{myParam}",
defaults: new { controller = "Foo", action = "Index" }
constraints: new { myParam= new MyCons() }
);