How to map multiple urls to the same controller/Action

Map multiple urls to the same controller/Action can be achieved by the custom route
Below example shows how write custom route

Custom  code  must be place in RouteConfig.cs.

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 :

multipleurls

Thanks to my friend manjunath for arise this question and make me find this solution

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s