I have this link in my Home/Index view:
<a asp-controller="About" asp-action="Index">About Link Test</a>
And this link in my About/Index view:
<a asp-controller="Home" asp-action="Index">Home Link Test</a>
I have a typical default route convention in Startup.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
When I run the app, I see the Home/Index view as expected. However when I click on the action, I get a 403 Forbidden as it attempts to treat the About route as a directory. The physical path displayed in the error displays is also odd, as it looks like it's trying to list the application root.
Now for the "sometimes" part. If I change my default route in Startup.cs to this:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=About}/{action=Index}/{id?}");
});
Then when I run the app I see the About/Index view as expected. The Home/Index action link works, and oddly so does the About/Index link on the Home/Index view! The same link that broke with a different controller default route.
I'm still fairly new to MVC in ASP.NET Core 3.1, so I'm sure this is a simple configuration issue or something, but I would appreciate any guidance on why the route isn't mapping correctly depending on the default route map!