更新时间:2023-02-15 12:51:35
一个不起作用的原因是因为您以错误的顺序注册了路由。从路线表的顶部到底部对路线进行评估,并且第一场比赛获胜。
One reason it doesn't work because you have the routes registered in the wrong order. The routes are evaluated from the top to the bottom of the route table and the first match wins.
另一个问题是,您需要将默认路线设置为区域路由(使用 MapAreaRoute
扩展方法),如果您希望它将请求定向到网站
区域。
Another issue is that you need to make the "default" route into an area route (using the MapAreaRoute
extension method) if you want it to direct requests to the Website
area.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "area",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapAreaRoute(
name: "default",
areaName: "Website",
template: "{controller=Home}/{action=Index}/{id?}");
});