On latest ASP.NET MVC CORE 2 default template, i am trying to change default action by modifying controller and action as below. I am expecting to see login page as default but i am having 404 http error. What I am doing wrong ?
You can verify this issue on default ASP.NET CORE 2 MVC project.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Account}/{action=Login}/{id?}");
});
}
If you look at the AccountController class, you'll see it's decorated with a Route attribute, like so:
[Route("[controller]/[action]")]
public class AccountController : Controller
However, if you look at the HomeController class, you'll see that it is not decorated with such an attribute:
public class HomeController : Controller
Because the AccountController is using Attribute routing, it will not be picked up using the Conventional routing template. The docs explain this mutual exclusivity:
Actions that define attribute routes cannot be reached through the conventional routes and vice-versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With