Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Legacy URL rewriting with query string parameters

I've looked at ASP.Net MVC routing legacy URLs passing querystring Ids to controller actions and several other similar posts for legacy URL routing, but I can't get past the error "The RouteData must contain an item named 'controller' with a non-empty string value." Looking this up on line didn't give me any hints to solve my problem.

I've implemented the Legacy routing class described in the link above, and this is what I've defined in the routing table:

        routes.Add(
            "Legacy", 
            new LegacyRoute("fooref.aspx", 
            "FooRef", 
            new LegacyRouteHandler())
        );

        routes.MapRoute(
            "FooRef",
            "{controller}/{action}",
            new
            {
                controller = "Home",
                action = "Index",
                foo_id = UrlParameter.Optional,
                bar_id = UrlParameter.Optional
            }
        );

When I use Phil Haack's route debugger, it indicates that fooref.aspx has a match, but when I turn the route debugger off, I get the error above. If I reverse the statement order, I get "Resource not found" for /ctprefer.aspx, which makes sense -- so it appears to be finding that as a valid route when put in the other order.

Where do I need to declare this missing controller reference?

Have routing requirements changed for ASP.NET MVC 2 RTM?

like image 804
John Kaster Avatar asked Mar 27 '10 03:03

John Kaster


1 Answers

The solution to this is to use an IHttpHandler directly, rather than an MVCHandler. I have posted code that works with MVC 3 to my blog: http://www.olsonsoft.com/blogs/stefanolson/post/Handling-Legacy-Urls-in-AspNet-MVC-3.aspx

...Stefan

like image 56
Stefan Avatar answered Oct 23 '22 09:10

Stefan