名为“默认路由”的路由已经路线收藏。路线名称必须是唯一

编程入门 行业动态 更新时间:2024-10-28 18:22:57
本文介绍了名为“默认路由”的路由已经路线收藏。路线名称必须是唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我发布 ASP.NET的WebAPI 解决远程 IIS服务器,我得到错误信息:

  

留言信息:System.ArgumentException:名为默认路由的路由已经路线收藏。路线名称必须是唯一的。

我看了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 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:

  • 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 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(...) { ... }

    更多推荐

    名为“默认路由”的路由已经路线收藏。路线名称必须是唯一

    本文发布于:2023-08-02 17:02:45,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1279560.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路由   路线   名称   收藏   是唯一

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!