Redigera

Dela via


RouteTable Class

Definition

Stores the URL routes for an application.

public ref class RouteTable
public class RouteTable
type RouteTable = class
Public Class RouteTable
Inheritance
RouteTable

Examples

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

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()
    ));
}
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 categoryRoute As Route
    
    urlPattern = "Category/{action}/{categoryName}"
    
    categoryRoute = New Route(urlPattern, New CategoryRouteHandler)
    
    routes.Add(categoryRoute)
End Sub

Remarks

Routes are URL patterns that are used for processing requests and that can be used to construct URLs dynamically. The Routes property is a static property (Shared in Visual Basic) that contains all the routes in an application that are used to specify how a URL request is matched to a class that handles the request. To specify a route, you add the route definition to the Routes property. Typically, you add routes to the Routes property from an event handler for the Application_Start event in the Global.asax file.

When an ASP.NET application handles a request, the application iterates through the collection of routes in the Routes property to find the route that matches the format of the URL request. The order of the routes that you add to the Routes property is significant, because the application uses the first route that it finds in the collection that matches the URL.

Constructors

RouteTable()

Initializes a new instance of the RouteTable class.

Properties

Routes

Gets a collection of objects that derive from the RouteBase class.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also