38

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>
0

7 Answers 7

80

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.

3
  • 27
    This was the case for me too. I renamed my project since I got the namespace wrong the first time, but the .dll, .pdb and .config files remained in the bin folder. It seems the MVC engine picks up everything that inherits from System.Web.HttpApplication and starts it up, including the routing.
    – helloserve
    Jun 17, 2015 at 8:20
  • 1
    Thank you @HenkRoux! I tried to do a "Clean Solution" but the folder kept the original files after the namespace change... have to manually delete them from the folder... Jul 24, 2017 at 15:18
  • Great solution, I was running out of ideas and considering rolling back commits! If anyone has this problem when deploying to Azure this should solve it (no need to go deleting bin folders etc)
    – d219
    Oct 17, 2018 at 11:04
24
  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.
1
  • I just had this issue because I inadvertently added a web project in the solution to the references of another web project. I did run clean, and I removed the reference, however, clean didn't remove the dll from the bin folder, so I had to delete it manually (Step 2 in your list) and it all started working.
    – boggy
    Dec 29, 2017 at 19:44
8

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)",
1
  • 1
    Yep - this fixed it for me after a project / namespace rename exercise Jun 28, 2017 at 12:37
4

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.

1
  • 1
    I will ignore policies because you deserve a great "Thank You".
    – HelloIT
    Jun 20, 2019 at 16:01
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.

1

I had this issue, the reason ended up being I had that web project referencing another web project. I just removed the reference, didn't need to clean the solution.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.