HttpMethodConstraint(String[]) Costruttore
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della classe HttpMethodConstraint usando i verbi HTTP consentiti per la route.
public:
HttpMethodConstraint(... cli::array <System::String ^> ^ allowedMethods);
public HttpMethodConstraint (params string[] allowedMethods);
new System.Web.Routing.HttpMethodConstraint : string[] -> System.Web.Routing.HttpMethodConstraint
Public Sub New (ParamArray allowedMethods As String())
Parametri
- allowedMethods
- String[]
Verbi HTTP validi per la route.
Eccezioni
Il valore del parametro allowedMethods
è null
.
Esempio
Nell'esempio seguente viene illustrato un Route oggetto la cui Constraints proprietà contiene un elemento con una chiave denominata httpMethod
e che ha un valore che è un'istanza della HttpMethodConstraint classe .
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);
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RegisterRoutes(RouteTable.Routes)
End Sub
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
Dim urlPattern As String
Dim reportRoute As Route
Dim allowedMethods() As String = {"GET", "POST"}
Dim methodConstraints As HttpMethodConstraint
methodConstraints = New HttpMethodConstraint(allowedMethods)
Dim constraintValues = New With {.httpMethod = methodConstraints}
urlPattern = "{locale}/{year}"
reportRoute = New Route(urlPattern, New ReportRouteHandler)
reportRoute.Constraints = New RouteValueDictionary(constraintValues)
routes.Add(reportRoute)
End Sub