Export (0) Print
Expand All

RouteCollection.MapPageRoute Method

Provides a way to define routes for Web Forms applications.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method MapPageRoute(String, String, String) Provides a way to define routes for Web Forms applications.
Public method MapPageRoute(String, String, String, Boolean) Provides a way to define routes for Web Forms applications.
Public method MapPageRoute(String, String, String, Boolean, RouteValueDictionary) Provides a way to define routes for Web Forms applications.
Public method MapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary) Provides a way to define routes for Web Forms applications.
Public method MapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary, RouteValueDictionary) Provides a way to define routes for Web Forms applications.
Top

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
Show:
© 2014 Microsoft