MVC中RouteAttribute 使用自定义路由约束
2019-01-11 本文已影响0人
凝碧_0e80
public class OAuthConstraintAttribute : System.Web.Routing.IRouteConstraint
{
const string name = "oAuth";
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return false;
}
}
DefaultInlineConstraintResolver defaultInlineConstraintResolver = new DefaultInlineConstraintResolver();
defaultInlineConstraintResolver.ConstraintMap.Add("oAuth", typeof(OAuthConstraintAttribute));
routes.MapMvcAttributeRoutes(defaultInlineConstraintResolver);