ASP.NET Core 2.1区域路由无法正常工作

Jia*_*nYA 3 c# asp.net .net-core asp.net-core

我的新区域有这个文件夹结构

在此输入图像描述

这是我在启动时设置它的方式:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");

    routes.MapRoute(
      name: "areas",
      template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
});
Run Code Online (Sandbox Code Playgroud)

这就是我创建basecontroller的方法

namespace App.Areas.Applications.Controllers
{
    [Area("Applications")]
    [Authorize]
    public abstract class ApplicationsBaseController : Controller
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的ApplicationsController然后继承BaseController

但是,当我设置这样的链接时

<li class="nav-item"><a asp-area="Applications" asp-controller="Applications" asp-action="Index" class="nav-link">Applications</a></li>
Run Code Online (Sandbox Code Playgroud)

这是我的网址https:// localhost:44338/Applications?area = Applications中显示的链接,我找不到页面.

在设置我的区域时我错过了什么?

编辑:

当我在[区域("应用程序")]之后添加[路径("应用程序/ [控制器]")]时,出现此错误

处理请求时发生未处理的异常.AmbiguousActionException:匹配多个动作.以下操作匹配路由数据并满足所有约束:

App.Areas.Applications.Controllers.ApplicationsController.Index(App)App.Areas.Applications.Controllers.ApplicationsController.Create(App)App.Areas.Applications.Controllers.ApplicationsController.NewRole(App)

ryk*_*mol 6

把它放在默认路线之前......就像这样

app.UseMvc(routes =>
{
 routes.MapRoute(
  name: "areas",
  template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);

routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢 。我爱你 (2认同)