1

To say that routing is not my strong suite is an understatement, so please bear with me.

I have this link in one of my pages and I need my MVC route to pick this up and map it to the

"MyArea" area "MessagesController" controller "Inbox" method

http://localhost/MyArea/messages/list.asp?pjid=&box=in&sf=mesibox

What I've come up with so far does not cut it.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.IgnoreRoute("favicon.ico");

routes.MapRoute(
    "Messages", 
    "messages/list.asp", 
    new
        {
            controller = "Messages", 
            action = "Inbox"
        });

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new
        {
            controller = "Account",
            action = "LogOn",
            id = UrlParameter.Optional
        }
    );

Any help would be appreciated.

Thank you, Stephen

UPDATE: Darin answered a similar question here How to route legacy QueryString parameters in ASP.Net MVC 3? so that takes care of the query string parameters. Now to figure out the main segments.

Community
  • 1
  • 1
Stephen Patten
  • 6,333
  • 10
  • 50
  • 84
  • 1
    have you considered using the IIS Rewrite Module? It's free, part of IIS7 and above, from Microsoft. It lets you "rewrite" requests on the server side, so that if you received a request for an ASP page, with query params, you could transform it into a request for ASPNET MVC, using the values of the params as segments in the url path. http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/ – Cheeso Jun 22 '12 at 00:37
  • That might work, but I think this first pass I'd like to keep the code inside the mvc project if possible. – Stephen Patten Jun 22 '12 at 00:53
  • Well you can easily response.redirect from the asp page assuming it still exists. I don't think you can tell an MVC area to intercept requests from outside of it's area. Wait. Is MyArea used by both ASP and MVC? I have never heard of doing that – Brian White Jun 22 '12 at 04:14
  • Brian, it's a long story, but it boils down to this: I'm programmatically grabbing pages from the old asp site and pulling them into the portion of the master page where I need and injecting it as a partial. So some of the links that are out of my control point back to the mvc site.. make sense? – Stephen Patten Jun 22 '12 at 04:46

1 Answers1

1

You seem to have defined an area, so it is inside the routing configuration of this area that you may try adding that route and not inside global.asax:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "MyArea_default",
        "MyArea/messages/list.asp",
        new { controller = "messages", action = "inbox" }
    );

    context.MapRoute(
        "MyArea_default",
        "MyArea/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Darin answered the question right on the money, just be aware that in my case mvc4 , that the constraints have to be unique e.g. "MyArea_default" and "MyArea_default". – Stephen Patten Jun 22 '12 at 16:32