A new .net core web application project comes with the following route configuration:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
If you replace this with app.UseMvc()
and add appropriate Route
attributes for both HomeController and its actions (Index, About, Contact, Error), it would still work. Since we're not specifying a default route, the default view (Home/Index) will not be rendered if you hit http://localhost:25137/. Hope that understanding is correct!
Now, since I need the default view to be shown when the http://localhost:25137/ is hit, I changed the routing code to app.UseMvcWithDefaultRoute();
which by definition will do the equivalent to the initial snippet. Even then, it was not rendering the default view; but worked when used the complete URL(http://localhost:25137/home/index). That means the routing still works but not the default one!
Then I went back to the controller and removed all the Route
attribute from the HomeController and its actions. Then the default routing worked with out any issues.
Is that the expected behavior? What could be the reason behind this behavior?