HttpMethodConstraint Classe

Definição

Permite que você defina quais verbos HTTP são permitidos quando o roteamento do ASP.NET determina se uma URL corresponde a uma rota.Enables you to define which HTTP verbs are allowed when ASP.NET routing determines whether a URL matches a route.

public ref class HttpMethodConstraint : System::Web::Routing::IRouteConstraint
public class HttpMethodConstraint : System.Web.Routing.IRouteConstraint
type HttpMethodConstraint = class
    interface IRouteConstraint
Public Class HttpMethodConstraint
Implements IRouteConstraint
Herança
HttpMethodConstraint
Implementações

Exemplos

O exemplo a seguir mostra um Route objeto cuja Constraints propriedade contém um item que tem uma chave chamada httpMethod e que tem um valor que é uma instância da HttpMethodConstraint classe.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);
}
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

Comentários

A HttpMethodConstraint classe permite que você limite a correspondência de rota para determinados VERBOS http.The HttpMethodConstraint class enables you to limit route matching to certain HTTP verbs. Por exemplo, você pode especificar que uma rota seja considerada uma correspondência para uma URL somente quando o verbo HTTP para a solicitação for POST .For example, you can specify that a route is considered a match for a URL only when the HTTP verb for the request is POST.

Para definir restrições para correspondência de rota, defina a Constraints propriedade da Route classe como uma instância da RouteValueDictionary classe.To set constraints for route matching, you set the Constraints property of the Route class to an instance of the RouteValueDictionary class. Para definir uma restrição de verbo HTTP, defina o valor de um elemento Dictionary para um HttpMethodConstraint objeto e a chave para qualquer nome.To set an HTTP verb constraint, you set the value of one dictionary element to an HttpMethodConstraint object and the key to any name.

No HttpMethodConstraint método, você inclui todos os VERBOS http que são permitidos para a rota quando o roteamento de ASP.NET determina se a rota corresponde a uma URL.In the HttpMethodConstraint method, you include all the HTTP verbs that are allowed for the route when ASP.NET routing determines whether the route matches a URL.

Construtores

HttpMethodConstraint(String[])

Inicializa uma nova instância da classe HttpMethodConstraint usando os verbos HTTP que são permitidos para a rota.Initializes a new instance of the HttpMethodConstraint class by using the HTTP verbs that are allowed for the route.

Propriedades

AllowedMethods

Obtém a coleção de verbos HTTP permitidos para a rota.Gets the collection of allowed HTTP verbs for the route.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection)

Determina se a solicitação foi feita com um verbo HTTP que é um dos verbos permitidos para a rota.Determines whether the request was made with an HTTP verb that is one of the allowed verbs for the route.

MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Implantações explícitas de interface

IRouteConstraint.Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection)

Para obter uma descrição desse membro, confira Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection).For a description of this member, see Match(HttpContextBase, Route, String, RouteValueDictionary, RouteDirection).

Aplica-se a