swagger .net 核心 API 模棱两可的动作错误 HTTP 方法 [英] swagger .net core API ambiguous HTTP method for Action Error
问题描述
使用 .net Core 2 API 实现 Swashbuckle/Swagger 我现在在访问 swagger.json 时收到 500 错误:
Implementing Swashbuckle/Swagger with .net Core 2 API I am now receiving the 500 error when accessing swagger.json:
NotSupportedException:操作的 HTTP 方法不明确 -EBisAPI.Controllers._class.HandleError (EBisAPI).行动需要一个Swagger 的显式 HttpMethod 绑定
NotSupportedException: Ambiguous HTTP method for action - EBisAPI.Controllers._class.HandleError (EBisAPI). Actions require an explicit HttpMethod binding for Swagger
我已经浏览了所有控制器,并看到了每个控制器的所有公共方法的显式路由.有没有办法确定哪种方法引发了不明确的路由错误?
I have gone through all the controllers and see explicit routing on all the public methods of each controller. Is there a way to determine which method is throwing the ambiguous routing error?
推荐答案
当一个方法在控制器中被声明为 public,但没有 REST 属性时,就会发生这种情况.将方法更改为受保护可能会解决该问题.
This can occur when a method is declared public in a controller, but without REST attributes. Changing the method to protected may address the issue.
我以前见过这个错误,通常错误消息指向罪魁祸首:EBisAPI.Controllers._class.HandleError
I have seen this error before and usually the errormessage points to the culprit:
EBisAPI.Controllers._class.HandleError
我猜 HandleError
是您基类中的 public
方法,对吗?将其更改为 protected
并重试.
I guess HandleError
is a public
method in your base class, right? Change it to protected
and try again.
这篇关于swagger .net 核心 API 模棱两可的动作错误 HTTP 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!