3

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?

1
  • have you got any solution? please let me know.. Commented Dec 3, 2014 at 7:49

1 Answer 1

1

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"} });
Sign up to request clarification or add additional context in comments.

2 Comments

how to solve the same problem with 4.0 non-MVC project? I have same condition same parameters but need to rediect to different page? i have same issue! i mean to say how to decide the destination page depending on URL eg:1. routes.MapPageRoute("carriers", "{state}/{mcat}/{dcat}", "~/carriers.aspx"); 2.routes.MapPageRoute("phones", "{state}/{mcat}/{dcat}", "~/phones.aspx"); if value in URL second parameter i.e mcat=cellphone then it must redirect to carriers.aspx. and if mcat=iphone then it must redirect to phones.aspx page how to do? any idea?
@SHEKHARSHETE did you get any solution for this??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.