← back to the blog


RouteCollection setup all route to go to one action

Posted in C#, ASP.NET MVC by dake

This will make the url to always go to Home Controller's Index action.


  routes.MapRoute(
                "AllUrl",
                "{*url}",
                new { controller = "Home", action = "Index" }
            );

This route will catch all the url, but if you have any other url you need to define before this one. For example, you want to define following test url.So when url hit /test, then will go to home/test action.


   routes.MapRoute(
               "TestRouteName",
               "test",
               new { controller = "Home", action = "test" }
           );

  routes.MapRoute(
                "AllUrl",
                "{*url}",
                new { controller = "Home", action = "Index" }
            );