Programing

"x"라는 이름의 경로가 이미 경로 모음에 있습니다.

lottogame 2020. 8. 27. 08:09
반응형

"x"라는 이름의 경로가 이미 경로 모음에 있습니다. 경로 이름은 고유해야합니다. ASP.NET MVC 3의 예외


ASP.NET MVC 3 웹 서비스를 수행 중이며이 예외가 간헐적으로 계속 발생합니다.

스택 추적 :

Server Error in '/' Application.

A route named 'ListTables' 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 'ListTables' is already in the route collection. Route names must be unique.
Parameter name: name

Source Error: 


Line 24:            //     }
Line 25:            // );
Line 26:             context.MapRoute(
Line 27:                 "ListTables",
Line 28:                 // example: 

Source File: C:\inetpub\wwwroot\SchemaBrowserService\Website\Areas\Api\ApiAreaRegistration.cs    Line: 26 

Stack Trace: 


[ArgumentException: A route named 'ListTables' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.Routing.RouteCollection.Add(String name, RouteBase item) +2329682
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +236
   System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults, Object constraints, String[] namespaces) +59
   System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults) +17
   SchemaBrowserService.Areas.Api.ApiAreaRegistration.RegisterArea(AreaRegistrationContext context) in C:\inetpub\wwwroot\SchemaBrowserService\Website\Areas\Api\ApiAreaRegistration.cs:26
   System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +105
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +199
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +45
   System.Web.Mvc.AreaRegistration.RegisterAllAreas() +6
   Website.MvcApplication.Application_Start() in C:\Users\djackson\Downloads\RestApiMvc3\Website\Website\Global.asax.cs:35

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

아마도 Route Debugger가 내가 수정하거나 삭제 한 오래된 경로가 있음을 보여주고 (내 컴퓨터를 재부팅 한 후에도) 사라지지 않을 것이라는 사실과 관련이있을 것입니다. 스택 추적은 또한 오랫동안 삭제되어 내 앱이 새 위치로 이동되고 그 이후로 정리되고 다시 빌드 된 소스 파일을 참조합니다. 내가 무엇을 놓치고 있습니까?

내 모든 경로 등록 코드는 다음과 같습니다.

// in Global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "Default2", // Route name
        "Api/{controller}/{action}/{id}", // URL with parameters
        new { controller = "DataSource", action = "Index", area = "Api", id = UrlParameter.Optional } // Parameter defaults
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
}

// in ApiAreaRegistration.cs:
public class ApiAreaRegistration : AreaRegistration
{
    public override string AreaName { get { return "Api"; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        // DataSources

        // Tables
        context.MapRoute(
            "ListTables",
            // example: 
            // /api/DataSources/DataSource/1/schemata/schema/dbo/tables
               "Api/DataSources/DataSource/{dataSourceId}/schemata/{schemaName}/tables",
            new
            {
                controller = "Tables",
                action = "TableList",
                schemaName = "dbo",
                dataSourceId = "DefaultId"
            }
        );


        // Schemata
        context.MapRoute(
          "Schema",
            // example: 
            // /api/DataSources/DataSource/1/schemata/schema/dbo
              "Api/DataSources/DataSource/{dataSourceId}/schemata/{schemaName}",
          new
          {
              controller = "Schema",
              action = "Schema",
              dataSourceId = "DefaultId",
              schemaName = UrlParameter.Optional
          }
       );

       // // DataSources
        context.MapRoute(
            "SingleDataSource",
            "Api/DataSources/DataSource/{dataSourceId}",
            new
            {
                controller = "DataSource",
                action = "DataSource",
                dataSourceId = UrlParameter.Optional
            }
        );
        context.MapRoute(
            "ListDataSources",
            "Api/DataSources",
            new
            {
                controller = "DataSource",
                action = "DataSourceList",
                dataSourceId = "DefaultId"
            }
        );
        context.MapRoute(
             "Api_default",
             "Api/{controller}/{action}/{id}",
             new { action = "Index", id = UrlParameter.Optional }
        );

    }
}

이 문제를 해결하기 위해 프로젝트의 bin 폴더로 이동하여 모든 DLL 파일을 삭제 한 다음 다시 빌드해야했습니다.


이 오류는 여러 원인으로 인해 발생할 수 있으며 동일한 오류가 발생하여 Global.asax 클래스를 수정하여 해결했습니다.

The Application_Start method at Global.asax.cs was like:

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

The following line occurs twice in this method:

RouteConfig.RegisterRoutes(RouteTable.Routes);

This ensured that the route was twice added to the route list and at the same time causing the error.

I changed the Application_Start method as follows and the error disappeared:

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

This may not be the answer for your problem, but can perhaps help others in the future. I didn't see this answer between the others, so I decided to add this.


I found out that Global.asax was referring to an old version of the site's DLL file before I renamed it. The DLL was not being cleaned up when I did Build > Clean up because the VS project/solution didn't refer to it any more. It seems that sometimes only the newer version of the DLL was being used, allowing the site to work correctly, but eventually both of them would be loaded causing the route conflicts.


The routes get loaded from all assemblies within AppDomain.CurrentDomain, so if your old assemblies are still part of that, you might be still getting old/duplicate routes.


Deleting the DLLs alone didn't work for me (in VS2013), but deleting the entire 'bin' and 'obj' folders and then building the solution worked perfectly! Makes me wish I hadn't spent so long trying to fix it...


In my case, I faced with this issue, when I added reference to another project from solution, which also was MVC and use the same names in area (I didn't want to added this project, I don't know how it happened). When I removed this DLL, project started to work.


None of the suggestions worked for me. Went ahead and restarted the web server (IIS in this case) and that cleared the error after I had fixed the code. DLL must have been cached in IIS.


I am getting same error. But finally I have got solution. Scenario: I am adding different(mvc4 application) dll in my web api mvc4 application. When try to run. I am getting same error. Root Cause- When my web api application run .Application register all area from self and start loading to current application domain dll references. When application load dll(MVC4 application) that time getting error because current maproute already add key for "HelpPage_Default".

Solution. 1.Change key for RegisterArea in maproute either current application or existing application(Refer dll). 2.Move code dll(mvc4 application) code to different liberary and refer to new dll.


I was manually calling AttributeRoutingHttpConfig.Start() in my Global.asax. Did not notice this auto-generated line at the top of the file which automatically calls it.

[assembly: WebActivator.PreApplicationStartMethod(typeof(Mev.Events.Web.AttributeRoutingHttpConfig), "Start")]

I had an application that was a Forms app migrated to MVC with a third party component used for authentication which redirected to another site. The component would start a session twice if the user wasn't already logged in (once for initial connection to site and once for return). So I solved this with the following code:

if (routes.Count < 3)
            {
                routes.IgnoreRoute("login.aspx");
                routes.IgnoreRoute("default.aspx");
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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


Deleting the dlls in the bin folder did work 100%, I still had dlls my project needed to rebuild. Rather make a copy of the bin folder. then delete the original.rebuild the project. if it fails, place the missing dlls into the bin folder.


I was running an old MVC2 website and I got this issue because the IIS 'Managed Pipeline Mode' was set on 'Integrated' by default (press F4 on the project). Changing it to 'Classic' fixed the issue


try this code, only change name

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

참고URL : https://stackoverflow.com/questions/10986909/a-route-named-x-is-already-in-the-route-collection-route-names-must-be-unique

반응형