Route.Constraints Property

 

Gets or sets a dictionary of expressions that specify valid values for a URL parameter.

Namespace:   System.Web.Routing
Assembly:  System.Web (in System.Web.dll)

member Constraints : RouteValueDictionary with get, set

Property Value

Type: System.Web.Routing.RouteValueDictionary

An object that contains the parameter names and expressions.

The Constraints property enables you to limit acceptable values for a URL parameter that is processed by a route. You assign a RouteValueDictionary object to the Constraints property. Each element in the RouteValueDictionary object contains the name of a parameter and one of the following:

  • A string that defines a regular expression. The regular expression is case-insensitive.

  • An object that implements the IRouteConstraint interface and that includes a Match method.

The HttpMethodConstraint class implements the IRouteConstraint interface. You can include an instance of the HttpMethodConstraint class as a constraint to specify which HTTP verbs are acceptable for the route.

The following example shows how to create a Route object and set the Constraints, DataTokens, and Defaults properties.

No code example is currently available or this language may not be supported.

The following example shows a Route object whose Constraints property contains a parameter named httpMethod with an instance of the HttpMethodConstraint class for the value.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show: