I have seen a few similar posts, but none are quite the same because in my question, I want to remove the HOME controller form the URL but the controller to remain as the default (so when my site loads from site.com/ the Index in my Home controller is fired)!!
My MVC4 website has several controllers, such as
Home
Products
Details
AndAnother
YetAnother
The Home controller is my default controller, and is where my home page lives, about page, contact us etc
I want to remove the HOME from the URL but this is still my default controller. All other controllers should remain with the controller name.
The following doesn't work, please note the default controller "WhatControllerGoesHere"
routes.MapRoute(
name: "HomeController",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "WhatControllerGoesHere", action = "Index", id = UrlParameter.Optional }
);
If I make both default controller HOME, I can't navigate to any other controller
routes.MapRoute(
name: "HomeController",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
So, the URLs I'm trying to achieve would be (where about and contact us are views in my Home)
site.com/ //note, no Home/
site.com/about //note, no Home/
site.com/contact //note, no Home/
site.com/products/
site.com/products/other
site.com/details/
site.com/details/other
site.com/details/AndAnother
I know I can create new routers for each controller but I'd rather avoid that if possible.