添加更多路由到asp.net MVC Global.asax

Not*_*ing 8 asp.net asp.net-mvc

我有一个地图路线,如:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );



    }
Run Code Online (Sandbox Code Playgroud)

但我想添加更多的路由URL,我该怎么做?

Bal*_*a R 9

只需添加另一个 MapRoute()

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

routes.MapRoute(
    "SecondRoute",
    "{controller}/{action}/{tags}",
    new { controller = "Products", action = "Index", tags = "" }
);
Run Code Online (Sandbox Code Playgroud)

我建议你通过这个关于路由的优秀帖子.