RouteCollection.MapPageRoute Method

.NET Framework (current version)
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides a way to define routes for Web Forms applications.

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

NameDescription
System_CAPS_pubmethodMapPageRoute(String, String, String)

Provides a way to define routes for Web Forms applications.

System_CAPS_pubmethodMapPageRoute(String, String, String, Boolean)

Provides a way to define routes for Web Forms applications.

System_CAPS_pubmethodMapPageRoute(String, String, String, Boolean, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

System_CAPS_pubmethodMapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

System_CAPS_pubmethodMapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

This method is provided for coding convenience. It is equivalent to calling the Add method and passing a Route object that is created by using the PageRouteHandler class.

The following example shows how to define routes for a Web Forms application by using this method. The example shows a method named RegisterRoutes that is called from Application_Start in the Global.asax file. The method uses each overload of MapPageRoute to add a route to the application. For more information about how to define routes for Web Forms applications, see How to: Define Routes for Web Forms Applications.

Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.MapPageRoute("",
        "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx")

    routes.MapPageRoute("SalesSummaryRoute",
        "SalesReportSummary/{locale}", "~/sales.aspx")

    routes.MapPageRoute("SalesDetailRoute",
        "SalesReportDetail/{locale}/{year}/{*queryvalues}", "~/sales.aspx",
        False)

    routes.MapPageRoute("SalesCurrentYearRoute",
        "SalesReportCurrent/{locale}/{year}/{*queryvalues}", "~/sales.aspx",
        false,
        new RouteValueDictionary(New With _ 
            { .locale = "US", .year = DateTime.Now.Year.ToString()}))

    routes.MapPageRoute("ExpenseCurrentYearRoute",
        "ExpenseReportCurrent/{locale}", "~/expenses.aspx",
        false,
        new RouteValueDictionary(New With _
            { .locale = "US", .year = DateTime.Now.Year.ToString()}),
        new RouteValueDictionary(New With _
            { .locale = "[a-z]{2}", .year = "\d{4}" }))

    routes.MapPageRoute("ExpenseDetailRoute",
        "ExpenseReportDetail/{locale}/{year}/{*queryvalues}", "~/expenses.aspx",
        false,
        new RouteValueDictionary(New With _
            { .locale = "US", .year = DateTime.Now.Year.ToString()}),
        new RouteValueDictionary(New With _ 
            { .locale = "[a-z]{2}", .year = "\d{4}" }),
        new RouteValueDictionary(New With _
            { .account = "1234", .subaccount = "5678" }))
End Sub
Return to top
Show: