How to map a classic asp request to an mvc control

2019-06-04 22:25发布

问题:

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.

回答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 }
    );
}