In this post we are going toย discuss about how to map multiple URLsย to the same controller/Action by the custom route.
Below example shows how write custom route
Custom code must be place inside the RouteConfig.cs.
1 2 3 4 5 6 7 8 9 10 11 |
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "MultipleUrls", "{phaseone,phasetwo}", new { controller = "home", action = "index", id = "" } ); routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}",defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } |
Explanation :
- ย MultipleUrls : Descripe the name of the route
- ย {phaseone,phasetwo} : controllers name with comma separator
- ย new { controller = “home”, action = “index”, id = “” } : It describe, where want to redirect for the above controllers
ย OUTPUT :
Thanks to my friend manjunath for rise this question and make me find this solution
thank you it was so useful