动作错误的swagger .net核心API模棱两可的HTTP方法

swagger .net core API ambiguous HTTP method for Action Error(动作错误的swagger .net核心API模棱两可的HTTP方法)
本文介绍了动作错误的swagger .net核心API模棱两可的HTTP方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 .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?

推荐答案

当方法在控制器中声明为公共但没有 REST 属性时,可能会发生这种情况.将方法更改为 protected 可能会解决问题.

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 kind of error before and usually the error message 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.

这当然只是一种可能的解决方案.如果错误消息中提到的方法是接口实现的一部分,则它不起作用,您需要查看其他解决方案之一.

This is of course only one possible solution. If the method which is mentioned in the error message is part of an interface implementation, it doesn't work and you need to look at one of the other solutions.

这篇关于动作错误的swagger .net核心API模棱两可的HTTP方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)