8

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?

2
  • Is this still a valid question or was it temporal? Did you ever find a solution? Commented Nov 25, 2010 at 6:07
  • No, haven't found a solution to it yet. Perhaps MVC 3 allows me to resolve it. Haven't looked back at this for a while. Commented Nov 29, 2010 at 22:45

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Stefan. This looks interesting. I'm not sure it would work with a data-driven approach to url direction, but it looks like it works for pre-declared lists. I don't know when I'll be able to get back to working on this, but it looks like what you wrote should work, based on code perusal only. I'll mark this as the accepted answer and if I get back to working on this code, I'll give it a full test.
0

You might want to take a look at URL Rewrite module for IIS. It can be used to translate legacy URL to your new MVC URLs without 'polluting' your app with legacy routes.

Don't know if it will fit your solution but it's worth having an alternative.

1 Comment

Jakub, thanks for the suggestion. I am aware of this functionality. I was looking for something controlled at the web application level rather than the server level, since this web application may be hosted on other IIS servers in the future that wouldn't be administered by my team.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.