Прочетете на английски Редактиране

Споделяне чрез


Route Constructors

Definition

Initializes a new instance of the Route class.

Overloads

Route(String, IRouteHandler)

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

Route(String, RouteValueDictionary, IRouteHandler)

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

Route(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.

Route(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.

Route(String, IRouteHandler)

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

C#
public Route(string url, System.Web.Routing.IRouteHandler routeHandler);

Parameters

url
String

The URL pattern for the route.

routeHandler
IRouteHandler

The object that processes requests for the route.

Examples

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

C#
void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Add(new Route
    (
         "Category/{action}/{categoryName}"
         , new CategoryRouteHandler()
    ));
}

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Route(String, RouteValueDictionary, IRouteHandler)

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

C#
public Route(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.IRouteHandler routeHandler);

Parameters

url
String

The URL pattern for the route.

defaults
RouteValueDictionary

The values to use for any parameters that are missing in the URL.

routeHandler
IRouteHandler

The object that processes requests for the route.

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Route(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.

C#
public Route(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints, System.Web.Routing.IRouteHandler routeHandler);

Parameters

url
String

The URL pattern for the route.

defaults
RouteValueDictionary

The values to use if the URL does not contain all the parameters.

constraints
RouteValueDictionary

A regular expression that specifies valid values for a URL parameter.

routeHandler
IRouteHandler

The object that processes requests for the route.

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Route(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.

C#
public Route(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints, System.Web.Routing.RouteValueDictionary dataTokens, System.Web.Routing.IRouteHandler routeHandler);

Parameters

url
String

The URL pattern for the route.

defaults
RouteValueDictionary

The values to use if the URL does not contain all the parameters.

constraints
RouteValueDictionary

A regular expression that specifies valid values for a URL parameter.

dataTokens
RouteValueDictionary

Custom values that are passed to the route handler, but which are not used to determine whether the route matches a specific URL pattern. These values are passed to the route handler, where they can be used for processing the request.

routeHandler
IRouteHandler

The object that processes requests for the route.

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1