Route Class

Route Class


Provides properties and methods for defining a route and for obtaining information about the route.

Namespace:   System.Web.Routing
Assembly:  System.Web (in System.Web.dll)

public class Route : RouteBase

System_CAPS_pubmethodRoute(String, IRouteHandler)

Initializes a new instance of the Route class, by using the specified URL pattern and handler class.

System_CAPS_pubmethodRoute(String, RouteValueDictionary, IRouteHandler)

Initializes a new instance of the Route class, by using the specified URL pattern, default parameter values, and handler class.

System_CAPS_pubmethodRoute(String, RouteValueDictionary, RouteValueDictionary, IRouteHandler)

Initializes a new instance of the Route class, by using the specified URL pattern, default parameter values, constraints, and handler class.

System_CAPS_pubmethodRoute(String, RouteValueDictionary, RouteValueDictionary, RouteValueDictionary, IRouteHandler)

Initializes a new instance of the Route class, by using the specified URL pattern, default parameter values, constraints, custom values, and handler class.


Gets or sets a dictionary of expressions that specify valid values for a URL parameter.


Gets or sets custom values that are passed to the route handler, but which are not used to determine whether the route matches a URL pattern.


Gets or sets the values to use if the URL does not contain all the parameters.


Gets or sets a value that indicates whether ASP.NET routing should handle URLs that match an existing file.(Inherited from RouteBase.)


Gets or sets the object that processes requests for the route.


Gets or sets the URL pattern for the route.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Returns information about the requested route.(Overrides RouteBase.GetRouteData(HttpContextBase).)


Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetVirtualPath(RequestContext, RouteValueDictionary)

Returns information about the URL that is associated with the route.(Overrides RouteBase.GetVirtualPath(RequestContext, RouteValueDictionary).)


Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodProcessConstraint(HttpContextBase, Object, String, RouteValueDictionary, RouteDirection)

Determines whether a parameter value matches the constraint for that parameter.


Returns a string that represents the current object.(Inherited from Object.)

The Route class enables you to specify how routing is processed in an ASP.NET application. You create a Route object for each URL pattern that you want to map to a class that can handle requests that correspond to that pattern. You then add the route to the Routes collection. When the application receives a request, ASP.NET routing iterates through the routes in the Routes collection to find the first route that matches the pattern of the URL.

Set the Url property to a URL pattern. The URL pattern consists of segments that come after the application name in an HTTP request. For example, in the URL, the pattern applies to products/show/beverages. A pattern with three segments, such as {controller}/{action}/{id}, matches the URL Each segment is delimited by the / character. When a segment is enclosed in braces ( and ), the segment is referred to a URL parameter. ASP.NET routing retrieves the value from the request and assigns it to the URL parameter. In the previous example, the URL parameter action is assigned the value show. If the segment is not enclosed in braces, the value is treated as a literal value.

Set the Defaults property to a RouteValueDictionary object that includes values that are used if a parameter is missing from the URL or to set additional values that are not parameterized in the URL. Set the Constraints property to a RouteValueDictionary object that contains values that are either regular expressions or IRouteConstraint objects. These values are used to determine whether a parameter value is valid.

The following example shows how to create a Route object and add it to the Routes property.

.NET Framework
Available since 3.5

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft