2

is it possible to redirect a static seo "friendly" url address to a controller/action without loosing the original address?

For example:

How can I make this work on ASP.NET MVC 2.0?

I was having a look at here and here with no luck during tests.

Community
  • 1
  • 1
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
  • It is not only possible but it's also one of the great features of ASP.NET MVC. The fact that you can map your URLs to any controller/action (rather than having the URL dictate the class/file to render) is a great feature. The solution that @JOBG suggests looks correct. – Hector Correa Jun 23 '11 at 13:26

1 Answers1

3

In Global.asax define a route like:

 routes.MapRoute(
                   "findEmployess",                                              // Route name
                   "find-the-best-employees",                           // URL with parameters
                   new { controller = "SearchEmployee", action = "Index" }  // Parameter defaults
               );

For this to work you need to use the route-name when generating the url, using this html helper

<%: Html.RouteLink("Search Employees","findEmployess")%>

Also you need to define this route before the default route:

//Your custom routes goes HERE before the default route

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
JOBG
  • 4,544
  • 4
  • 26
  • 47