-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Describe the bug
Form POST action not mapping to controller/action after upgrading .NET 5 to .NET 6 preview 7.
We upgraded our .NET 5 MVC project to 6 preview 7. After the upgrade the login page does show as usual, but the login action does not reach the POST action on the controller.
I have no idea what could be the reason for this issue.
To Reproduce
Startup cs:
We have multiple areas but the login method is located in the last route defined ( the non-area/root controllers). Maybe this mapping has something to do with the issue (please note that the mapping did work correctly in .NET 5). Some text is replaced with *.
app.UseEndpoints(endpoints =>
{
// Area Routes
endpoints.MapAreaControllerRoute(
"***_dyn_api_route",
"***DynApi",
"***Api/{controller=Dynamic}/{action=HandleRequest}/{entityName:alpha:required}/{actionName:alpha:required}");
endpoints.MapAreaControllerRoute(
"***_api_route",
"***Api",
"***Api/{controller}/{action}/{id?}");
endpoints.MapAreaControllerRoute(
"***_app_route",
"***App",
"***App/{controller}/{action}/{id?}");
endpoints.MapAreaControllerRoute(
"***_sso_route",
"***Sso",
"***Sso/{controller=Users}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
"***_***_route",
"******",
"******/{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
"***_payment_route",
"***",
"***/{controller=Payment}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
"***_***_route",
"******",
"******/{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
"***_KnowledgeBase_route",
"***KnowledgeBase",
"***Knowledgebase/{controller=KnowledgeBase}/{action=Index}/{id?}");
// The root controllers route (that contains the Login controller)
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Login}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
Index.cshtml:
<form asp-action="Index" asp-controller="Login" asp-antiforgery="true">
Rendered result:
The rendered HTML is the same in .NET 5 and 6 so the tag helpers did not change.
<form action="/" method="post">
Controller post method:
Not changed after the upgrade. The action is located in the HomeController. Please note that the GET method is working correctly.
[ValidateAntiForgeryToken]
[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> Index(SignInModel model){
}