【问题标题】:Azure deployment: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique. Parameter name: nameAzure 部署:名为“HelpPage_Default”的路由已在路由集合中。路由名称必须是唯一的。参数名称:名称
【发布时间】:2018-04-27 21:19:51
【问题描述】:

当我在本地运行时,网站运行良好。但是当部署在微软Azure上时,就会出现上述错误。

我已经尝试从 bin 文件夹和 obj 文件夹中删除 .DLL 文件,但问题仍然存在。

堆栈跟踪:

[ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.Routing.RouteCollection.Add(String name, RouteBase item) +3213863
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +203
   System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults, Object constraints, String[] namespaces) +56
   Makewayy.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) +87
   System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +104
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +190
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +34
   Makewayy.WebApiApplication.Application_Start() +12

[HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +10104513
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10085804
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)

路由配置:-

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

区域注册 -

namespace Makewayy.Areas.HelpPage
{
    public class HelpPageAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "HelpPage";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "HelpPage_Default",
                "Help/{action}/{apiId}",
                new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });

            HelpPageConfig.Register(GlobalConfiguration.Configuration);
        }
    }
}

【问题讨论】:

  • 请给我们路由配置代码。
  • @ChetanRanpariya 添加。
  • AreaRegistration 怎么样?你在那里检查过吗?
  • 我检查了 AreaRegistration ,但它看起来配置正确,但我注意到 HelpPage_Default 存在于此处,是否需要从此处删除?
  • 尝试删除它,看看是否有效。

标签: c# asp.net-mvc asp.net-mvc-4 azure-web-app-service


【解决方案1】:

名为“HelpPage_Default”的路由已在路由集合中。路由名称必须是唯一的。

根据我的理解,您需要确保您没有多次定义名为 HelpPage_Default 的路由。此外,您需要检查您的代码并确保AreaRegistration.RegisterAllAreas(); 只能被调用一次。

此外,请确保您的应用程序可以在本地运行。在发布到天蓝色网站之前,您可以使用kudu 并清空D:\home\site\wwwroot 下的网页内容,然后重新部署您的应用程序。

【讨论】:

  • 我启动了 HelpPage_Default Route ,并清除了 site\wwwroot 内容并再次部署,它工作了谢谢@Bruce Chen
  • 我第一次调用 AreaRegistration.RegisterAllAreas();
  • 我之前重命名了这个项目。单击“清理解决方案”时未清理旧的 DLL。删除 bin 文件夹中的所有文件为我修复了它。
  • @Soenhay 还在我的项目中进行了重命名,删除 bin 文件夹也为我修复了它。谢谢。
【解决方案2】:

特别是在重命名文件后部署到 Azure,接受的答案here 可能就是答案。当我在本地部署时一切正常,并且清理/删除 bin 文件夹什么也没做,工作是什么。

  1. 在 Visual Studio 发布屏幕上单击配置
  2. 在新窗口中单击垂直设置选项卡
  3. 扩展文件发布选项
  4. 勾选“删除目标位置的其他文件”复选框。

【讨论】:

  • 太棒了。我刚刚也遇到了这个问题,我很困惑。这立即解决了它。
【解决方案3】:

如果清理 bin 文件夹仍然没有帮助,可能是因为您不小心在项目中添加了对解决方案的另一个 API 的引用(这将注册两个 API 的路由配置 -> 哎哟!)。

【讨论】:

    【解决方案4】:

    我在重命名项目、重命名文件夹结构并更改 .sln 文件以反映这些更改后遇到此错误。我尝试清洁解决方案,但这对我不起作用。我不得不删除 bin 文件夹的内容,然后我就解决了这个错误。

    【讨论】:

      猜你喜欢
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 2012-06-14
      • 1970-01-01
      • 2012-04-24
      • 2019-10-15
      • 1970-01-01
      相关资源
      最近更新 更多