2

When I run locally the website runs fine. But when deployed on Microsoft Azure , it is throwing the above error occurs.

I already tried deleting the .DLL Files from bin folder and obj folder, but the problem still exist.

Stack Trace:

[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)

Route Configuration:-

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 }
            );
        }
    }
}

AreaRegistration -

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);
        }
    }
}
d219
  • 2,707
  • 5
  • 31
  • 36

4 Answers4

3

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

Per my understanding, you need to make sure that you have not defined the route named HelpPage_Default no more than once. Also, you need to check your code and make sure that AreaRegistration.RegisterAllAreas(); could only be called once.

Moreover, please make sure your application could work on your local side. And before publishing it to azure website, you could use kudu and empty the web content under D:\home\site\wwwroot, then redeploy your application.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • I commected the HelpPage_Default Route , and cleared the site\wwwroot content and deployed again , it worked thankyou @Bruce Chen – Rachit Rastogi Nov 15 '17 at 04:49
  • I am getting this error with a brand new project on the first time that it calls AreaRegistration.RegisterAllAreas(); – Soenhay May 30 '18 at 18:31
  • 2
    I previously renamed the project. The old DLL's were not cleaned when clicking "Clean Solution." Deleting all files in the bin folder fixed it for me. – Soenhay May 30 '18 at 19:55
  • @Soenhay also did a renaming in my project and deleting bin folder fixed it for me too. Thanks. – Alexander Jun 20 '18 at 11:57
1

Specifically for deploying to Azure after renaming files the accepted answer here is likely the answer. All worked fine when I deployed locally, and cleaning/deleting bin folder did nothing, what did work was.

  1. On the Visual Studio publish screen click Configure
  2. From the new Window click the vertical Settings tab
  3. Expand File Publish Options
  4. Tick the 'Remove additional files at destination' checkbox.

enter image description here

d219
  • 2,707
  • 5
  • 31
  • 36
  • 1
    Brilliant. I just ran into this issue as well, and I was quite stumped. This solved it instantly. – kdhansen Jun 01 '19 at 21:58
1

I encountered this error after I renamed my project, renamed the folder structure and altered the .sln file to reflect these changes. I tried cleaning the solution but that didn't work for me. I had to delete the contents of the bin folder and then I got past the error.

Dan Leksell
  • 510
  • 5
  • 6
0

If cleaning your bin folder still doesn't help, maybe it's because you have accidentally added a reference to another API of your solution in your project (which would register route config of both APIs -> Ouch!).

Eva Buchet
  • 91
  • 4