IRouteConstraint.Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection) 方法

定义

确定 URL 参数是否包含此约束的有效值。Determines whether the URL parameter contains a valid value for this constraint.

public:
 bool Match(System::Web::HttpContextBase ^ httpContext, System::Web::Routing::Route ^ route, System::String ^ parameterName, System::Web::Routing::RouteValueDictionary ^ values, System::Web::Routing::RouteDirection routeDirection);
public bool Match (System.Web.HttpContextBase httpContext, System.Web.Routing.Route route, string parameterName, System.Web.Routing.RouteValueDictionary values, System.Web.Routing.RouteDirection routeDirection);
abstract member Match : System.Web.HttpContextBase * System.Web.Routing.Route * string * System.Web.Routing.RouteValueDictionary * System.Web.Routing.RouteDirection -> bool

参数

httpContext
HttpContextBase

一个对象,封装有关 HTTP 请求的信息。An object that encapsulates information about the HTTP request.

route
Route

此约束所属的对象。The object that this constraint belongs to.

parameterName
String

正在检查的参数的名称。The name of the parameter that is being checked.

values
RouteValueDictionary

一个包含 URL 的参数的对象。An object that contains the parameters for the URL.

routeDirection
RouteDirection

一个对象,指示在处理传入请求或生成 URL 时,是否正在执行约束检查。An object that indicates whether the constraint check is being performed when an incoming request is being handled or when a URL is being generated.

返回

如果 URL 参数包含有效值,则为 true;否则为 falsetrue if the URL parameter contains a valid value; otherwise, false.

注解

使用Match方法可为约束添加验证逻辑。You use the Match method to add validation logic for the constraint. 当处理传入请求和构造 URL 时, 路由框架会调用此方法。This method is called by the routing framework when an incoming request is processed and when a URL is constructed. 可以通过检查routeDirection参数确定当前方案。You can determine the current scenario by examining the routeDirection parameter.

处理请求时, 路由框架确定传入请求的模式和值是否与路由的模式和约束匹配。When a request is processed, the routing framework determines whether the pattern and values of the incoming request match the pattern and constraints of the route. 构造 URL 时, 路由框架将确定调用GetVirtualPath方法时提供的值是否与路由的模式和约束匹配。When a URL is constructed, the routing framework determines whether the values supplied when the GetVirtualPath method is called match the pattern and constraints of the route.

适用于

另请参阅