Depending on url, I want to route different controllers. So depending on different URLs directed to same DNS server, I want to give my website a different look and feel.
To test this locally I tried:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"localhost",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Contact", id = UrlParameter.Optional }
);
}
}
Wat I wanted was the Contact page to appear, not the default Home Page as the URL was :/localhost:portnr./.
How can I get the first bit of an URL (domain) to decide which controller to route?