RouteCollection.MapPageRoute Method
Provides a way to define routes for Web Forms applications.
Assembly: System.Web (in System.Web.dll)
| Name | Description | |
|---|---|---|
![]() | MapPageRoute(String, String, String) | Provides a way to define routes for Web Forms applications. |
![]() | MapPageRoute(String, String, String, Boolean) | Provides a way to define routes for Web Forms applications. |
![]() | MapPageRoute(String, String, String, Boolean, RouteValueDictionary) | Provides a way to define routes for Web Forms applications. |
![]() | MapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary) | Provides a way to define routes for Web Forms applications. |
![]() | MapPageRoute(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.
void RegisterRoutes(RouteCollection routes) { 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 { { "locale", "US" }, { "year", DateTime.Now.Year.ToString() } }); routes.MapPageRoute("ExpenseCurrentYearRoute", "ExpenseReportCurrent/{locale}", "~/expenses.aspx", false, new RouteValueDictionary { { "locale", "US" }, { "year", DateTime.Now.Year.ToString() } }, new RouteValueDictionary { { "locale", "[a-z]{2}" }, { "year", @"\d{4}" } }); routes.MapPageRoute("ExpenseDetailRoute", "ExpenseReportDetail/{locale}/{year}/{*queryvalues}", "~/expenses.aspx", false, new RouteValueDictionary { { "locale", "US" }, { "year", DateTime.Now.Year.ToString() } }, new RouteValueDictionary { { "locale", "[a-z]{2}" }, { "year", @"\d{4}" } }, new RouteValueDictionary { { "account", "1234" }, { "subaccount", "5678" } }); }
