0

I want to create some SEO friendly URL.

Following is my Global.ascx entry:


 routes.MapRoute(
     "Product",
     "{action}/{param1}/{id}",
     new { controller = "Home", action = "Index" });

 routes.MapRoute(
     "Default",
     "{controller}/{action}/{id}",
     new { controller = "Home", action = "Index", id = UrlParameter.Optional });

First Mapping is because i don't want to display my controller name in url. Next Mapping is for rest of the URL.

Problem is there are some URL which gives me an error like:


http://localhost:1234/index/my-product-information/12  : PASS
http://localhost:1234/contentcontrol/index             : PASS
http://localhost:1234/contentcontrol/index/12          : FAIL

here, index : ACTION NAME contentcontrol : Controller Name

How should i resolve this.

Thanks in advance.

1 Answer 1

0

The problem you've got is that there's nothing to differentiate your first route from your second when it comes to requests to URLs with 3 segments, so the first route catches all those requests and 'hides' the second one. To get around it you'll have to differentiate the two routes, for example by making the first route pattern:

"/Go/{action}/{param1}/{id}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.