I have added a new HttpPost route "api/export/error/" to my WebApi, using Attribute Routing, and I am getting an error:
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
But I do not have the same routes in different controllers that i see; here are the only routes in those two controllers:
ExportErrorController.cs
[HttpGet]
[Route( "api/export/error/total/" )]
[HttpGet]
[Route( "api/export/error/channel/{channelId}/" )]
[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}/" )]
I cannot see any places that have the same between the two controllers
Apparently ASP.Net does not evaluate parameter 'types' OR methods when determining the route to use so it found and matched the route text "error" as a potential parameter for 'channelid' even though they were different methods.
Adding a type to the parameter helped it resolve it properly so:
[Route( "api/2/export/{channelId}/" )]
Is fixed by changing it to:
[Route( "api/2/export/{channelId:int}/" )]
来源:https://stackoverflow.com/questions/36621459/asp-net-webapi-multiple-controller-types-were-found-that-match-the-url