Επεξεργασία

Κοινή χρήση μέσω


RouteCollection.MapPageRoute Method

Definition

Provides a way to define routes for Web Forms applications.

Overloads

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.

Examples

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" } });
}
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

Remarks

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.

MapPageRoute(String, String, String)

Provides a way to define routes for Web Forms applications.

public:
 System::Web::Routing::Route ^ MapPageRoute(System::String ^ routeName, System::String ^ routeUrl, System::String ^ physicalFile);
public System.Web.Routing.Route MapPageRoute (string routeName, string routeUrl, string physicalFile);
member this.MapPageRoute : string * string * string -> System.Web.Routing.Route
Public Function MapPageRoute (routeName As String, routeUrl As String, physicalFile As String) As Route

Parameters

routeName
String

The name of the route.

routeUrl
String

The URL pattern for the route.

physicalFile
String

The physical URL for the route.

Returns

The route that is added to the route collection.

Examples

The following example shows how to define a route by using this method. The first statement defines a route that does not have a name. The second statement defines a named route. This example is part of a larger example that is available in the MapPageRoute method overview.

routes.MapPageRoute("",
    "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx");

routes.MapPageRoute("SalesSummaryRoute",
    "SalesReportSummary/{locale}", "~/sales.aspx");
routes.MapPageRoute("",
    "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx")

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

Remarks

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.

See also

Applies to

MapPageRoute(String, String, String, Boolean)

Provides a way to define routes for Web Forms applications.

public:
 System::Web::Routing::Route ^ MapPageRoute(System::String ^ routeName, System::String ^ routeUrl, System::String ^ physicalFile, bool checkPhysicalUrlAccess);
public System.Web.Routing.Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess);
member this.MapPageRoute : string * string * string * bool -> System.Web.Routing.Route
Public Function MapPageRoute (routeName As String, routeUrl As String, physicalFile As String, checkPhysicalUrlAccess As Boolean) As Route

Parameters

routeName
String

The name of the route.

routeUrl
String

The URL pattern for the route.

physicalFile
String

The physical URL for the route.

checkPhysicalUrlAccess
Boolean

A value that indicates whether ASP.NET should validate that the user has authority to access the physical URL (the route URL is always checked). This parameter sets the CheckPhysicalUrlAccess property.

Returns

The route that is added to the route collection.

Examples

The following example shows how to define a route by using this method. This example is part of a larger example that is available in the MapPageRoute method overview.

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

Remarks

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.

See also

Applies to

MapPageRoute(String, String, String, Boolean, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

public:
 System::Web::Routing::Route ^ MapPageRoute(System::String ^ routeName, System::String ^ routeUrl, System::String ^ physicalFile, bool checkPhysicalUrlAccess, System::Web::Routing::RouteValueDictionary ^ defaults);
public System.Web.Routing.Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, System.Web.Routing.RouteValueDictionary defaults);
member this.MapPageRoute : string * string * string * bool * System.Web.Routing.RouteValueDictionary -> System.Web.Routing.Route
Public Function MapPageRoute (routeName As String, routeUrl As String, physicalFile As String, checkPhysicalUrlAccess As Boolean, defaults As RouteValueDictionary) As Route

Parameters

routeName
String

The name of the route.

routeUrl
String

The URL pattern for the route.

physicalFile
String

The physical URL for the route.

checkPhysicalUrlAccess
Boolean

A value that indicates whether ASP.NET should validate that the user has authority to access the physical URL (the route URL is always checked). This parameter sets the CheckPhysicalUrlAccess property.

defaults
RouteValueDictionary

Default values for the route parameters.

Returns

The route that is added to the route collection.

Examples

The following example shows how to define a route by using this method. This example is part of a larger example that is available in the MapPageRoute method overview.

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

Remarks

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.

See also

Applies to

MapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

public:
 System::Web::Routing::Route ^ MapPageRoute(System::String ^ routeName, System::String ^ routeUrl, System::String ^ physicalFile, bool checkPhysicalUrlAccess, System::Web::Routing::RouteValueDictionary ^ defaults, System::Web::Routing::RouteValueDictionary ^ constraints);
public System.Web.Routing.Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints);
member this.MapPageRoute : string * string * string * bool * System.Web.Routing.RouteValueDictionary * System.Web.Routing.RouteValueDictionary -> System.Web.Routing.Route
Public Function MapPageRoute (routeName As String, routeUrl As String, physicalFile As String, checkPhysicalUrlAccess As Boolean, defaults As RouteValueDictionary, constraints As RouteValueDictionary) As Route

Parameters

routeName
String

The name of the route.

routeUrl
String

The URL pattern for the route.

physicalFile
String

The physical URL for the route.

checkPhysicalUrlAccess
Boolean

A value that indicates whether ASP.NET should validate that the user has authority to access the physical URL (the route URL is always checked). This parameter sets the CheckPhysicalUrlAccess property.

defaults
RouteValueDictionary

Default values for the route.

constraints
RouteValueDictionary

Constraints that a URL request must meet in order to be processed as this route.

Returns

The route that is added to the route collection.

Examples

The following example shows how to define a route by using this method. This example is part of a larger example that is available in the MapPageRoute method overview.

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("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}" }))

Remarks

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.

See also

Applies to

MapPageRoute(String, String, String, Boolean, RouteValueDictionary, RouteValueDictionary, RouteValueDictionary)

Provides a way to define routes for Web Forms applications.

public:
 System::Web::Routing::Route ^ MapPageRoute(System::String ^ routeName, System::String ^ routeUrl, System::String ^ physicalFile, bool checkPhysicalUrlAccess, System::Web::Routing::RouteValueDictionary ^ defaults, System::Web::Routing::RouteValueDictionary ^ constraints, System::Web::Routing::RouteValueDictionary ^ dataTokens);
public System.Web.Routing.Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints, System.Web.Routing.RouteValueDictionary dataTokens);
member this.MapPageRoute : string * string * string * bool * System.Web.Routing.RouteValueDictionary * System.Web.Routing.RouteValueDictionary * System.Web.Routing.RouteValueDictionary -> System.Web.Routing.Route
Public Function MapPageRoute (routeName As String, routeUrl As String, physicalFile As String, checkPhysicalUrlAccess As Boolean, defaults As RouteValueDictionary, constraints As RouteValueDictionary, dataTokens As RouteValueDictionary) As Route

Parameters

routeName
String

The name of the route.

routeUrl
String

The URL pattern for the route.

physicalFile
String

The physical URL for the route.

checkPhysicalUrlAccess
Boolean

A value that indicates whether ASP.NET should validate that the user has authority to access the physical URL (the route URL is always checked). This parameter sets the CheckPhysicalUrlAccess property.

defaults
RouteValueDictionary

Default values for the route parameters.

constraints
RouteValueDictionary

Constraints that a URL request must meet in order to be processed as this route.

dataTokens
RouteValueDictionary

Values that are associated with the route that are not used to determine whether a route matches a URL pattern.

Returns

The route that is added to the route collection.

Exceptions

The routeUrl parameter is null.

Examples

The following example shows how to define a route by using this method. This example is part of a larger example that is available in the MapPageRoute method overview.

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" } });
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" }))

Remarks

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.

See also

Applies to