I have an ASP.NET MVC application where the default page should be index.html which is an actual file on disk.
I can browse to the file using www.mydomain.com/index.
ASP.Net MVC routing is controlled by the Global.asax
/ Global.asax.cs
files. The out-of-the-box routing looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
When no path is specified, ie. www.domain.tld/
, the route is the empty string, ""
. Therefore the routing looks for a controller with that name. In other words, it looks for a controller with no name at all. When it finds no such controller it serves up a 404 NOT FOUND
error page.
To solve the problem, either map that path to something meaningful or else ignore that route entirely, passing control over to the index.html file:
routes.IgnoreRoute("");