名为“默认路由”的路由已经路线收藏。路线名称必须是唯一 [英] A route named 'DefaultRoute' is already in the route collection. Route names must be unique
问题描述
当我发布 ASP.NET的WebAPI
解决远程 IIS服务器
,我得到错误信息:
留言信息:System.ArgumentException:名为默认路由的路由已经路线收藏。路线名称必须是唯一的。
块引用>我看了<一个href=\"http://stackoverflow.com/questions/10986909/a-route-named-x-is-already-in-the-route-collection-route-names-must-be-unique\">this同样的问题线程,但没有上工作过。我曾尝试:
- 删除的所有项目的所有斌/ OBJ文件夹。
- 清洁/重建
- 删除关闭远程服务器上的文件发布前
- 重命名项目
反正我可以找出是否有一个陈旧的文件。我做了一些重命名文件和我听说,这可能会导致一个问题?
不知道这是否重要,但我使用ASP.NET的WebAPI与RestSharp一起让我休息的电话。
这是我的
的Global.asax启动
有:?它是多余的。AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);
解决方案当我有code,明确设定使用
RouteAttribute
路线名字,我得到这个错误,当我试图建立,将取决于它是否被调用HTTP GET或HTTP POST采取不同参数的路线:[HTTPGET]
[路线(MyApiMethodNAME =MyApiMethod)]
公共MyApiMethod PropertyData(...)
{
...
}//错误:导致System.ArgumentException:名为默认路由的路由已经是路由集合的路线名称必须是唯一的。
[HttpPost]
[路线(MyApiMethodNAME =MyApiMethod)]
公共MyApiMethod PropertyData(...)
{
...
}这是没有立即对我来说很明显,但问题原来是什么错误消息说:我有两个路径具有相同
名称
值。只是改变那些名称
值是唯一的(无需顶部更改路线本身或方法签名)解决了该问题:[HTTPGET]
[路线(MyApiMethodNAME =MyApiMethod-GET)]
公共MyApiMethod PropertyData(...)
{
...
}[HttpPost]
[路线(MyApiMethodNAME =MyApiMethod-POST)]
公共MyApiMethod PropertyData(...)
{
...
}When I publish an
ASP.NET WebAPI
solution to a remoteIIS Server
, I get the error message:Message: System.ArgumentException: A route named 'DefaultRoute' is already in the route collection. Route names must be unique.
I saw this thread with the same problem, but nothing on it has worked. I have tried:
- Deleting all bin/obj folders in all projects.
- Cleaning/Rebuilding
- Deleting files off the the remote server before publishing
- Renaming the project
Is there anyway I can find out if there is a stale file. I did rename some files and I heard that this can cause a problem?
Not sure if this matters, but I am using the ASP.NET WebApi along with RestSharp to make my rest calls.
This is what my
Global.asax startup
has: Is it redundant?AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); RouteConfig.RegisterRoutes(RouteTable.Routes);
解决方案I got this error when I had code that explicitly setting route names using a
RouteAttribute
, when I was trying to set up a route that would take different arguments depending on whether it was called with HTTP GET or HTTP POST:[HttpGet] [Route("MyApiMethod", Name = "MyApiMethod")] public MyApiMethod PropertyData(...) { ... } // ERROR: Causes "System.ArgumentException: A route named 'DefaultRoute' is already in the route collection. Route names must be unique." [HttpPost] [Route("MyApiMethod", Name = "MyApiMethod")] public MyApiMethod PropertyData(...) { ... }
This wasn't immediately obvious to me, but the problem turned out to be exactly what the error message says: I had two routes with the same
Name
value. Just changing thoseName
values to be unique (without needing top change the route itself or the method signatures) fixed the issue:[HttpGet] [Route("MyApiMethod", Name = "MyApiMethod-GET")] public MyApiMethod PropertyData(...) { ... } [HttpPost] [Route("MyApiMethod", Name = "MyApiMethod-POST")] public MyApiMethod PropertyData(...) { ... }
这篇关于名为“默认路由”的路由已经路线收藏。路线名称必须是唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!