IRouteConstraint 接口

定义

定义类必须实现才能检查某 URL 参数值是否对约束有效的协定。Defines the contract that a class must implement in order to check whether a URL parameter value is valid for a constraint.

public interface class IRouteConstraint
public interface IRouteConstraint
type IRouteConstraint = interface
Public Interface IRouteConstraint
派生

注解

如果在路由定义中包含 URL 参数的约束, 则必须将该约束表示为字符串, 或者表示为实现IRouteConstraint接口的对象。When you include a constraint for a URL parameter in a route definition, you must represent the constraint as either string or as an object that implements the IRouteConstraint interface. 如果约束是一个字符串, 则将其视为正则表达式。If the constraint is a string, it is treated as a regular expression. 当无法将验证逻辑作为IRouteConstraint正则表达式轻松表示时, 可以创建一个实现的类。You create a class that implements IRouteConstraint when you cannot represent the validation logic easily as a regular expression. Match方法中添加验证逻辑。You add the validation logic in the Match method.

方法

Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection)

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

适用于

另请参阅