Same url for two pages in asp.net web routing

I am working on routing a webpage url. I want two routes 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 the virtual path data, I only redirect the url that is written on top of the global file.

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

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

      

Return Vpd route for route 1. How can I generate both URLs for two different pages?

+3


source to share


1 answer


First option: You use route constraints to restrict browser requests that match a specific route. You can use a regular expression to specify a route restriction.

The second option: . You can use a constant parameter to distinguish between routes that have the same parameter number and type.



For example:.

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

      

+1


source







All Articles