Asp.net web api exception only after deploying at IIS : A route named 'HelpPage_Default' is already in the route collection

32

I've read this question and tried the solutions mentioned there but I'm getting this exception only after i published the application to IIS of a remote server. In my local computer's IIS the application is working fine. I've no clue what is causing this exception at that server:

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name
Source Error:  
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

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) +3713577
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +350
   System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults, Object constraints, String[] namespaces) +95
   XbimServer.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) +174
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +323
   BimServer.WebApiApplication.Application_Start() +23

[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) +12600317
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[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) +12617364
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12456981

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212

Here's what I've set up at Global.asax.cs:

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

My RouteConfig.cs:

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

And my WebApiConfig.cs:

config.MapHttpAttributeRoutes();

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

I've also made the following change to my web.config file:

<system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
asp.net-mvc
iis
asp.net-web-api
asked on Stack Overflow Dec 29, 2014 by Aminul

6 Answers

66

I just ran into the same issue. I think the error was caused because I had pushed another solution to my site previously and there were leftover files that were somehow getting in the way.

To fix this I checked the box that says "Remove additional files at destination" while publishing through Visual Studio to my Azure site. I would assume you could just manually delete any old files that were on the server before publishing as well. After this the site ran fine with no errors.

answered on Stack Overflow Feb 13, 2015 by Tibincrunch
21
  1. Right click your solution in Visual Studio -> click Clean Solution
  2. Remove all files under your \Project\bin\ folders
  3. Rebuild your solution in Visual Studio Cheers.
answered on Stack Overflow Apr 14, 2016 by (unknown user)
4

I renamed a Namespace by refactoring it and doing that missed this hardcoded string:

Project > Areas > HelpPage > AppStart:

public static class HelpPageConfig
    {
        [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
            MessageId = "<CORRECT NAMESPACE>.Areas.HelpPage.TextSample.#ctor(System.String)",
answered on Stack Overflow May 26, 2017 by Jeremy Thompson
2

I have the same issue after renamed the project name. So,

  1. Find & Replace the correct name across the entire solution.
  2. Clean solution
  3. Delete bin & obj folder of the project.
  4. Rebuild solution

..yes, it works.

answered on Stack Overflow Sep 15, 2018 by King_Fisher
1

I had this same issue and tried multiple proposed solutions from different threads with similar issues and got nowhere.

I finally just checked out a clean copy of the solution from team explorer and that fixed it for me.

answered on Stack Overflow Apr 25, 2016 by aemorales1
0

I had the same issue when deploying application on Local IIS. My publish directory and IIS hosting directory are same. I tried with following steps, it worked for me:

  1. Click on Solution >> publish
  2. Delete existing file>> settings>> expand file publish options
  3. check checkbox Delete all existing files prior to publish is true;
  4. check checkbox Precompile during publishing is true.
answered on Stack Overflow Oct 1, 2019 by Santosh P

User contributions licensed under CC BY-SA 3.0