当我发布 ASP.NET的WebAPI 解决远程 IIS服务器,我得到错误信息:
留言信息:System.ArgumentException:名为默认路由的路由已经路线收藏。路线名称必须是唯一的。
我看了this同样的问题线程,但没有上工作过。我曾尝试:
反正我可以找出是否有一个陈旧的文件。我做了一些重命名文件和我听说,这可能会导致一个问题?
不知道这是否重要,但我使用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 remote IIS 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:
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 those Name 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(...) { ... }
更多推荐
名为“默认路由”的路由已经路线收藏。路线名称必须是唯一
发布评论