2016-04-14 191 views
2

我添加了一个新的HttpPost路线“API /导出/错误/”我的WebAPI,使用属性路由的网址,而我得到一个错误:ASP.net的WebAPI多个控制器类型中发现匹配

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.\r\n\r\nThe request has found the following matching controller types: \r\nMyApp.Controllers.ExportErrorController\r\nMyApp.Controllers.ExportGeneratorController

但我没有在我看到的不同控制器中有相同的路线;这里是在这两个控制器的唯一途径:

ExportErrorController.cs

[HttpGet] [Route("api/export/error/total/")]

​​

[HttpPost] [Route("api/export/error/")]

[HttpDelete] [Route("api/export/error/{id}/")]

[HttpPut] [Route("api/export/error/clear/")]

ExportGeneratorController.cs

[HttpGet] [Route("api/2/export/{channelId}/")]

[HttpPost] [Route("api/2/export/generate-word/{debugInfo}/")]

[HttpPost] [Route("api/2/export/generate-excel/{debugInfo}/")]

我看不到有两个控制器之间的相同的任何地方

回答

2

显然ASP.Ne t在确定要使用的路线时并不评估参数“类型”或方法,因此它找到并匹配路线文本“错误”作为'channelid'的潜在参数,尽管它们是不同的方法。

添加一个类型的参数,帮助它解决它妥善所谓: [Route("api/2/export/{channelId}/")]

是固定的,改成: [Route("api/2/export/{channelId:int}/")]

相关问题