C# 属性路由正在忽略谓词?

C# 属性路由正在忽略谓词?,c#,asp.net-web-api2,C#,Asp.net Web Api2,我认为当您有两个URL与请求匹配的路由时,属性路由无法根据指定的动词来区分它们 有人能告诉我为什么以及如何避免这个问题吗? 我创建了一个非常简单的web api 2项目来重现我的问题: 首先,在webapiconfig中,仅配置属性路由以避免路由匹配出现任何问题: public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API

我认为当您有两个URL与请求匹配的路由时,属性路由无法根据指定的动词来区分它们

有人能告诉我为什么以及如何避免这个问题吗?

我创建了一个非常简单的web api 2项目来重现我的问题:

首先,在webapiconfig中,仅配置属性路由以避免路由匹配出现任何问题:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();            
    }
}
然后,创建第一个控制器

[RoutePrefix("travelQueries")]
public class TravelQueriesController : ApiController
{
    [Route("", Name = "test1")]
    [HttpPost]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1" };
    }

    [Route("{id}", Name = "test1read")]
    [HttpGet]
    public string Get2()
    {
        return "value1" ;
    }
}
现在,如果注释/删除TravelQueriesController.Get2方法,它就可以工作了

这意味着Asp.NETWebAPI2认为当两个URL匹配时,HttpGet和HttpPost之间存在冲突

我认为这是一个bug,但可能不是,有人会告诉我原因:)

这是

我只是添加了这个问题,因为问题中有明确的错误信息,所以谷歌搜索可能更正确

[RoutePrefix("travelQueries")]
public class TravelQueriesFullController : ApiController
{
    [Route("full", Name = "test2")]
    [HttpPost]
    public IEnumerable<string> Get()
    {
        return new string[] { "value2" };
    }        
}
"Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.

The request has found the following matching controller types:   

WebApplication1.Controllers.TravelQueriesController

WebApplication1.Controllers.TravelQueriesFullController"