2016-04-14 184 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}/")]

相關問題