I'm using ASP.net MVC4 with VWD Express 2010. I've set up an extra route to remove the extraneous /Home/
from URLs, as suggested for example here and here. I made sure to put them in the right order:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Home",
url: "{action}",
defaults: new { controller = "Home", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
This works as far as removing /Home/
is concerned, but now I get 404 when trying to access non-default controllers:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /LogItem/
I've tracked it down to the route, since if I remove the non-default one, it works fine again. I'm not sure what I'm doing wrong however, and by my understanding of other answers and the docs, this should work.
Edit: Since it's apparently not clear from my description, I added the "Home" route to be able to link to /About/
instead of /Home/About
, etc. It was the suggested solution I found after googling. I basically want it to match actions implemented by HomeController
with shorthand URLs (/{action}
), as well as any other controller I also add in full (/{controller}/{action}/{optional id}
)