问题描述
我已使用属性路由将新的HttpPost路由"api/export/error/"添加到WebApi,但出现错误:
I have added a new HttpPost route "api/export/error/" to my WebApi, using Attribute Routing, and I am getting an error:
但是我在不同的控制器中没有相同的路由;这是这两个控制器中的唯一路由:
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
推荐答案
很明显,ASP.Net在确定要使用的路由时不评估参数类型"或方法,因此发现并匹配了路由文本错误""channelid"的参数,即使它们是不同的方法.
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.
在参数中添加类型有助于其正确解析,因此: [Route("api/2/export/{channelId}/")]
Adding a type to the parameter helped it resolve it properly so:[Route( "api/2/export/{channelId}/" )]
已通过将其更改为: [Route("api/2/export/{channelId:int}/")]
这篇关于ASP.net WebApi找到多个与URL匹配的控制器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!