views:

58

answers:

1

Please excuse the confusing title ;)

We've built an ASP.NET MVC application to replace our "old" ASP.NET webforms monster. We still want to support some of the old URLs used there, because these may still float around in E-Mails etc. somewhere out there.

For example: Our old system used the URL ~/Password.aspx, the URL in the new MVC system is ~/Home/Password.

To support these old URLs, we just added them to the route table, like

    routes.MapRoute(
        "Password",
        "Password.aspx",
        new {
            controller = "Home",
            action = "Password",
            id = ""
        }
    );

This works great, but whenever we use Url.Action("Password", "Home") in our code, it generates the old URL ("~/Password.aspx" instead of "~/Home/Password"). Since we want to slowly phase out the old URLs, it would be nice if the MVC routes still "understood" the old URLs but only use/write the new ones.

Is there a way to achieve this?

+5  A: 

Put the new route above the old route on the routing table. The higher up the route is, the more precedence it will have:

routes.MapRoute(
      "PasswordNew",
      "Home/Password",
      new {controller = "Home",
           action = "Password",
           id = "" 
       }
    );

routes.MapRoute(
        "Password",
        "Password.aspx",
        new {
            controller = "Home",
            action = "Password",
            id = ""
        }
    );
jchapa
I'd also suggest mapping the old URLs to something that *redirects* to the new URLs. This could also help search engines better index your site.
Levi
+1 - Excellent idea.
jchapa
Argl, so simple; how the f did I not think of this myself ;)Thanks a lot, it does not work for all URLs/routes in our case (some are pretty complicated) but for some.
saxx