名为&QUOT路由; X"已经路线收藏。路线名称必须是唯一的。异常的ASP.NET MVC 3 [英] A route named "x" is already in the route collection. Route names must be unique. Exception with ASP.NET MVC 3

查看:138
本文介绍了名为&QUOT路由; X"已经路线收藏。路线名称必须是唯一的。异常的ASP.NET MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个ASP.NET MVC 3 web服务,我不断收到间歇此异常。

堆栈跟踪:

 在'/'应用程序的服务器错误。名为ListTables路由已经路线收藏。路线名称必须是唯一的。
参数名:名称说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。异常详细信息:System.ArgumentException:名为ListTables路由已经路线收藏。路线名称必须是唯一的。
参数名:名称源错误:
第24行://}
第25行://);
第26行:context.MapRoute(
27号线:ListTables
第28行://例如:源文件:C:\\的Inetpub \\ wwwroot的\\ SchemaBrowserService \\网站\\区\\阿比\\ ApiAreaRegistration.cs行:26堆栈跟踪:
[ArgumentException的:一个名为ListTables路由已经路线收藏。路线名称必须是唯一的。
参数名:姓名]
   System.Web.Routing.RouteCollection.Add(字符串名称,RouteBase项目)2329682
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection路线,字符串名称,字符串的URL,对象的默认值,对象的限制,的String []命名空间)236
   System.Web.Mvc.AreaRegistrationContext.MapRoute(字符串名称,字符串的URL,对象的默认值,对象的限制,的String []命名空间)+59
   System.Web.Mvc.AreaRegistrationContext.MapRoute(字符串名称,字符串的URL,对象的默认值)+17
   SchemaBrowserService.Areas.Api.ApiAreaRegistration.RegisterArea在C(AreaRegistrationContext上下文):\\的Inetpub \\ wwwroot的\\ SchemaBrowserService \\网站\\区\\阿比\\ ApiAreaRegistration.cs:26
   System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection路线,对象状态)+105
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection路线,IBuildManager buildManager,对象状态)+199
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(对象状态)+45
   System.Web.Mvc.AreaRegistration.RegisterAllAreas()+6
   Website.MvcApplication.Application_Start()在C:\\用户\\ djackson \\下载\\ RestApiMvc3 \\网站\\网站\\的Global.asax.cs:35版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272

它可能涉及到一个事实,即路线调试器显示我有我修改或删除,并不会消失(甚至重新启动我的机器后)一些老路线。堆栈跟踪也指早已被删除,我的应用程序已被移动到一个新的位置,清洁,自那时以来,重建一个源文件。我缺少什么?

下面是我所有的路线报名code的:

  //在Global.asax.cs中:
公共静态无效的RegisterRoutes(RouteCollection路线)
{
    routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);
    routes.MapRoute(
        默认设置2,//路线名称
        原料药/ {控制器} / {行动} / {ID},// URL带参数
        新{控制器=数据源,行动=索引,面积=API,ID = UrlParameter.Optional} //参数默认
        );        routes.MapRoute(
            默认,//路线名称
            {控制器} / {行动} / {ID},// URL带参数
            新{控制器=家,行动=索引,ID = UrlParameter.Optional} //参数默认
        );    }保护无效的Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    的RegisterRoutes(RouteTable.Routes);
}//在ApiAreaRegistration.cs:
公共类ApiAreaRegistration:AreaRegistration
{
    公众覆盖字符串AREANAME {{返回API; }}    公共覆盖无效RegisterArea(AreaRegistrationContext上下文)
    {
        // 数据源        //表
        context.MapRoute(
            ListTables
            //例如:
            // / API /数据源/数据源/ 1 /图式/模式/ DBO /表
               原料药/数据源/数据源/ {}的DataSourceID /图式/ {} SCHEMANAME /表
            新
            {
                控制器=表,
                行动=TableList
                SCHEMANAME =DBO
                的DataSourceID =DefaultId
            }
        );
        //图式
        context.MapRoute(
          架构,
            //例如:
            // / API /数据源/数据源/ 1 /图式/模式/ DBO
              原料药/数据源/数据源/ {}的DataSourceID /图式/ {} SCHEMANAME
          新
          {
              控制器=模式,
              行动=模式,
              的DataSourceID =DefaultId
              SCHEMANAME = UrlParameter.Optional
          }
       );       // // 数据源
        context.MapRoute(
            SingleDataSource
            原料药/数据源/数据源/ {}的DataSourceID,
            新
            {
                控制器=数据源,
                行动=数据源,
                的DataSourceID = UrlParameter.Optional
            }
        );
        context.MapRoute(
            ListDataSources
            原料药/数据源,
            新
            {
                控制器=数据源,
                行动=DataSourceList
                的DataSourceID =DefaultId
            }
        );
        context.MapRoute(
             Api_default
             原料药/ {控制器} / {行动} / {ID}
             新{行动=索引,ID = UrlParameter.Optional}
        );    }
}


解决方案

要解决这个问题,我不得不进入bin文件夹在我的项目,删除所有的DLL文件,然后重建,这解决了问题。

I'm doing an ASP.NET MVC 3 web service and I keep getting this exception intermittently.

Stack trace:

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

It's probably related to the fact that Route Debugger shows that I have some old routes that I've modified or deleted and won't go away (even after rebooting my machine). The stack trace also refers to a source file that has long since been deleted and my app has been moved to a new location, cleaned and rebuilt since then. What am I missing?

Here is all of my route registration code:

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

    }
}

解决方案

To fix this problem I had to go into the bin folder on my project, delete all DLL files and then rebuild and this fixed the problem.

这篇关于名为&QUOT路由; X"已经路线收藏。路线名称必须是唯一的。异常的ASP.NET MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆