Waheed Ahmad
Waheed Ahmad

Reputation: 35

Same url for two pages in asp.net web routing

I am working on web page url routing. I want two route url with equal no. parameters, same pattern and same url but different route name. My routes are below.

Routes.MapPageRoute("Route1", "{parameter1}/{parameter2}", "packages.aspx");
Routes.MapPageRoute("Route2", "{parameter1}/{parameter2}", "destination.aspx", false, null, null,new RouteValueDictionary { { "isDestination", "yes"} });

When I call virtual path data, I am only redirecting on url that is written on top of global file.

 VirtualPathData vpd =RouteTable.Routes.GetVirtualPath(null,
               "Route1",
               "parameter1", "parameter2");

VirtualPathData vpd =RouteTable.Routes.GetVirtualPath(null,
               "Route2",
              "parameter1", "parameter2");

Vpd return route for Route1. How can I construct both url for two different pages?

Upvotes: 3

Views: 1320

Answers (1)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16134

First Option: You use route constraints to restrict the browser requests that match a particular route. You can use a regular expression to specify a route constraint.

Second Option: You can use constant parameter to distinguish between your routes which have same number & type of parameters.

Eg.:

Routes.MapPageRoute("Route1", "packages/{parameter1}/{parameter2}", "packages.aspx");
Routes.MapPageRoute("Route2", "destination/{parameter1}/{parameter2}", "destination.aspx", false, null, null,new RouteValueDictionary { { "isDestination", "yes"} });

Upvotes: 1

Related Questions