HttpMethodConstraint(String[]) Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans HttpMethodConstraint baru kelas dengan menggunakan kata kerja HTTP yang diizinkan untuk rute.
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())
Parameter
- allowedMethods
- String[]
Kata kerja HTTP yang valid untuk rute.
Pengecualian
Parameternya allowedMethods
adalah null
.
Contoh
Contoh berikut menunjukkan Route objek yang propertinya Constraints berisi item yang memiliki kunci bernama httpMethod
dan yang memiliki nilai yang merupakan instans HttpMethodConstraint kelas .
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