views:

149

answers:

1

I'm currently migrating a large website from WebForms to MVC. It's going to be a long process, I can't go through every page and migrate it right away, nor do I want to.

One of the issues I have is, in the old web app, we were doing some URL Rewriting for the WebForms stuff like so:

from: http://sample.com/id/123/name/Something/Page.aspx
to: http://sample.com/Page.aspx?id=123&name=Something

Basically it's: http://sample.com/[QueryString]/Page.aspx where the querystring is broken up and seperated by "/".

Is there anyway to do the samething with MVC Routing to support my legacy pages?

I've checked around SO and I saw interesting stuff, but nothing that seemed to directly answer my question. If I missed something, I'm sorry for the double post. Thank you in advance.

I'm willing to code each Route individually if I have to. Although I'm still not sure what I'd need to do there.

+1  A: 

You can't substitute, but you can augment. The ASP.NET Routes are required as part of the operation of ASP.NET MVC. However after you have defined your routes, or keep them the same, you can use a standard rewriter on top of them to give you more control over your URLs.

You see routes aren't actually URL Rewriting they are a lot like the namespace for the web. In that when you use your code namespace it defines where to go to find any object, the same is true for Routes when used with ASP.NET MVC. So when you have the following URL /products/shirts/1234 it maps directly to a method in the ProductsController called Shirts(int productId).

Where as with URL rewriting, you are modifying and augmenting the URL to something else. That relates down to a path your system will understand. But when you are done, you are not mapping the modified URL directly to a piece of code like you do with routes. You just changed the string from say /products/shirts/1234 to /products/shirts.aspx?id=1234.

But to answer your question directly. WebForms will not support Routing until .NET 4.0. There are ways to hack it on right now, but you may run in to upgrade troubles if you ever move to .NET 4.0

Nick Berardi
Thank you for your answer. I guess I still don't fully understand what Routing is doing exactly. I guess it's only to map a url to a Controller? Interesting.So you would recommend I just add in my URL Rewriter I was using in the "old" website, at least until .NET 4.0 comes out?
blesh
Don't worry it is a common thing to get Routing and Rewriting mixed up, I have seen some very famous developers make the same mistake. Well Routing won't handle all of what a URL Rewriter can do. Such as forcing www. on domains, checking headers, or redirects. Routing only has access to the Path part of the URL. So inorder to keep your site SEO friendly you will need your URL Rewriter to redirect the old URL's to the new ones.
Nick Berardi