Reputation: 95
I have an MVC application that when I browse to root (http://localhost:5000) when debugging it attempts to load index.html rather than taking me to {HomeController}/{Index}
If I build the application into a Docker image the route work as expected
All other Routes work as expected but this one, I can't see any reference to index.html anywhere in the project.
My route mapping (Startup.cs):
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
HomeController:
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
My views are setup as default:
Views
-Home
--Index.cshtml
Upvotes: 0
Views: 795
Reputation: 229
Are you using a route attribute on the controller ? if yes, then remove It and try again because when you use route attribute all your defined routes in UseMvc and UseMvcWithDefaultRoute() will be ignored Source.
Another solution is to add a route attribute before your index method :
[Route("")]
[Route("Home")]
[Route("Home/Index")]
public IActionResult Index()
{
return View();
}
Upvotes: 0