다음을 통해 공유


HttpMethodConstraint(String[]) 생성자

정의

경로에 허용되는 HTTP 동사를 사용하여 HttpMethodConstraint 클래스의 새 인스턴스를 초기화합니다.

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())

매개 변수

allowedMethods
String[]

경로에 유효한 HTTP 동사입니다.

예외

allowedMethods 매개 변수가 null인 경우

예제

다음 예제에서는 해당 Constraints 속성에 라는 httpMethod 키가 있고 클래스의 인스턴스인 값이 있는 항목을 포함하는 개체를 HttpMethodConstraint 보여 Route 줍니다.

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

적용 대상

추가 정보