Table of Contents

Class HttpRoute

Namespace
System.Web.Http.Routing
Assembly
System.Web.Http.dll

Represents a route class for self-host (i.e. hosted outside of ASP.NET).

public class HttpRoute : IHttpRoute
Inheritance
HttpRoute
Implements
Inherited Members

Constructors

HttpRoute()

Initializes a new instance of the HttpRoute class.

public HttpRoute()

HttpRoute(string)

Initializes a new instance of the HttpRoute class.

public HttpRoute(string routeTemplate)

Parameters

routeTemplate string

The route template.

HttpRoute(string, HttpRouteValueDictionary)

Initializes a new instance of the HttpRoute class.

public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults)

Parameters

routeTemplate string

The route template.

defaults HttpRouteValueDictionary

The default values for the route parameters.

HttpRoute(string, HttpRouteValueDictionary, HttpRouteValueDictionary)

Initializes a new instance of the HttpRoute class.

public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints)

Parameters

routeTemplate string

The route template.

defaults HttpRouteValueDictionary

The default values for the route parameters.

constraints HttpRouteValueDictionary

The constraints for the route parameters.

HttpRoute(string, HttpRouteValueDictionary, HttpRouteValueDictionary, HttpRouteValueDictionary)

Initializes a new instance of the HttpRoute class.

public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, HttpRouteValueDictionary dataTokens)

Parameters

routeTemplate string

The route template.

defaults HttpRouteValueDictionary

The default values for the route parameters.

constraints HttpRouteValueDictionary

The constraints for the route parameters.

dataTokens HttpRouteValueDictionary

Any additional tokens for the route parameters.

HttpRoute(string, HttpRouteValueDictionary, HttpRouteValueDictionary, HttpRouteValueDictionary, HttpMessageHandler)

Initializes a new instance of the HttpRoute class.

public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, HttpRouteValueDictionary dataTokens, HttpMessageHandler handler)

Parameters

routeTemplate string

The route template.

defaults HttpRouteValueDictionary

The default values for the route parameters.

constraints HttpRouteValueDictionary

The constraints for the route parameters.

dataTokens HttpRouteValueDictionary

Any additional tokens for the route parameters.

handler HttpMessageHandler

The message handler that will be the recipient of the request.

Properties

Constraints

Gets the constraints for the route parameters.

public IDictionary<string, object> Constraints { get; }

Property Value

IDictionary<string, object>

The constraints for the route parameters.

DataTokens

Gets any additional data tokens not used directly to determine whether a route matches an incoming HttpRequestMessage.

public IDictionary<string, object> DataTokens { get; }

Property Value

IDictionary<string, object>

Any additional data tokens not used directly to determine whether a route matches an incoming HttpRequestMessage.

Defaults

Gets the default values for route parameters if not provided by the incoming HttpRequestMessage.

public IDictionary<string, object> Defaults { get; }

Property Value

IDictionary<string, object>

The default values for route parameters if not provided by the incoming HttpRequestMessage.

Handler

Gets or sets the http route handler.

public HttpMessageHandler Handler { get; }

Property Value

HttpMessageHandler

The http route handler.

RouteTemplate

Gets the route template describing the URI pattern to match against.

public string RouteTemplate { get; }

Property Value

string

The route template describing the URI pattern to match against.

Methods

GetRouteData(string, HttpRequestMessage)

Determines whether this route is a match for the incoming request by looking up the HttpRouteData for the route.

public virtual IHttpRouteData GetRouteData(string virtualPathRoot, HttpRequestMessage request)

Parameters

virtualPathRoot string

The virtual path root.

request HttpRequestMessage

The HTTP request.

Returns

IHttpRouteData

The HttpRouteData for a route if matches; otherwise null.

GetVirtualPath(HttpRequestMessage, IDictionary<string, object>)

Attempts to generate a URI that represents the values passed in based on current values from the HttpRouteData and new values using the specified HttpRoute.

public virtual IHttpVirtualPathData GetVirtualPath(HttpRequestMessage request, IDictionary<string, object> values)

Parameters

request HttpRequestMessage

The HTTP request message.

values IDictionary<string, object>

The route values.

Returns

IHttpVirtualPathData

A HttpVirtualPathData instance or null if URI cannot be generated.

ProcessConstraint(HttpRequestMessage, object, string, HttpRouteValueDictionary, HttpRouteDirection)

Determines whether this instance equals a specified route.

protected virtual bool ProcessConstraint(HttpRequestMessage request, object constraint, string parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)

Parameters

request HttpRequestMessage

The HTTP request.

constraint object

The constraints for the route parameters.

parameterName string

The name of the parameter.

values HttpRouteValueDictionary

The list of parameter values.

routeDirection HttpRouteDirection

One of the enumeration values of the enumeration.

Returns

bool

true if this instance equals a specified route; otherwise, false.