HttpMethodConstraint Constructor (String[])
.NET Framework (current version)
Initializes a new instance of the HttpMethodConstraint class by using the HTTP verbs that are allowed for the route.
Assembly: System.Web (in System.Web.dll)
Parameters
- allowedMethods
-
Type:
System.String[]
The HTTP verbs that are valid for the route.
| Exception | Condition |
|---|---|
| ArgumentNullException | The allowedMethods parameter is null. |
The following example shows a Route object whose Constraints property contains an item that has a key named httpMethod and that has a value that is an instance of the HttpMethodConstraint class.
void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { string[] allowedMethods = { "GET", "POST" }; HttpMethodConstraint methodConstraints = new HttpMethodConstraint(allowedMethods); Route reportRoute = new Route("{locale}/{year}", new ReportRouteHandler()); reportRoute.Constraints = new RouteValueDictionary { { "httpMethod", methodConstraints } }; routes.Add(reportRoute); }
.NET Framework
Available since 3.5
Available since 3.5
Show: