Azure 部署:路由集合中已存在名为 'HelpPage_Default' 的路由。路由名称必须是唯一的。参数名称:名称

Azure deployment: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique. Parameter name: name

当我在本地 运行 时,网站 运行 没问题。但是在Microsoft 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);
        }
    }
}

A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.

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

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

专门用于在重命名文件后部署到 Azure,接受的答案可能是 here。当我在本地部署时一切正常,cleaning/deleting bin 文件夹什么也没做,起作用的是。

  1. 在 Visual Studio 发布屏幕上单击配置
  2. 在新的 Window 中单击垂直设置选项卡
  3. 展开文件发布选项
  4. 勾选 'Remove additional files at destination' 复选框。

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

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