ASP.NET Route All Url Go to Single Action

2015/10/311 min read
bookmark this
Responsive image

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" }
            );