【问题标题】:Unable to route back from the Manage area in ASP.NET Core MVC 3.1无法从 ASP.NET Core MVC 3.1 中的管理区域路由回
【发布时间】:2020-09-11 04:02:10
【问题描述】:
  1. 我有一个默认的普通客户和相关控制器的正常未命名区域:Conrollers。 Controllers forlder 中的控制器上没有任何与区域相关的属性。
  2. 我还有“管理”区域,其中包含区域\管理\控制器文件夹中的用户管理相关控制器。
  3. 我在管理区域的控制器具有属性:[Area("Manage")](我认为属于:“不能混合基于常规和属性的路由。在这些情况下,后者获胜”,但不知道如何解决这个问题)。
  4. 这是 Startup.cs 的摘录:
           app.UseEndpoints(endpoints =>
            {

                endpoints.MapControllerRoute(
                    name: "areas",
                    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "categoryFilter",
                    pattern: "product/{action}/{category?}",
                    defaults: new { controller = "Product", action = "List" });

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
  1. 我需要更改哪些内容才能解决我的问题 我可以正常浏览该站点,直到找到与带有“管理”标签并放置在“管理”区域中的控制器相关的视图。一旦我点击这些视图,所有其他标准视图都会收到“/Manage/”路径,我无法返回它们:
    最初的主页是:https://localhost:12345/,联系人是 https://localhost:12345/Contact
    但后来它变成:https://localhost:44311/Managehttps://localhost:12345/Manage/Contact

【问题讨论】:

    标签: asp.net-mvc asp.net-core routes asp.net-mvc-routing


    【解决方案1】:

    当使用 Url.RouteUrl() 或 Url.Action() 并且您没有在路由数据中指定 area 属性时, 它停留在最新的区域, 例如(在管理/测试时):

    @Url.Action("Index", "Home"); //returns /Manage
    @Url.Action("Index", "Home", new { area = "" }); //returns /
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 2017-12-30
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      相关资源
      最近更新 更多