问题
I migrated an asp.net core 2.2 app to 3.0 today, took a bit but everything recompiles and the front (default) works fine, but i can't access the back (separate area). I have my endpoints specified as such (more specific first as the migration documentation recommends) :
app.UseEndpoints(endpoints =>
endpoints.MapAreaControllerRoute("areas", "areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}");
});
This is the exact configuration i had with UseMVC and endpoints disabled in 2.2
Accessing any url in my area (i only have one) /Back leads to a blank page
There is absolutely nothing of value in the debug output window when running in debug mode with debugger attached :
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/2.0 GET https://localhost:44355/Back/
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 10.9489ms 404
I have found a debugger for routes at https://haacked.com/archive/2008/03/13/url-routing-debugger.aspx/ but it dates from 2008 so i doubt that would work with endpoint routing.
Is there anything i can do to check what's happening in the endpoint resolution?
Also just to confirm it's not a view problem not a crash in the controller when i manually go to /back/home/index it doesn't ever go in the corresponding function (breakpoint set on first line)
回答1:
I fixed it by going with a static url start instead of the {area:exists} as i found that in a sample online, this doesn'ts sound like a "clean" fix but it does fix my issue so my solution was to go from
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute("areas", "areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}");
});
To
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute("Back", "Back", "back/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}");
});
Also note sure if it caused the issue or if it was already there but it broke identity ui routing (only that area has authentication so now instead of a blank page i'm redirected to /Identity/... as expected, but that page is now blank)
来源:https://stackoverflow.com/questions/58250609/issue-after-migrating-from-2-2-to-3-0-default-works-but-cant-access-area-is-t