当在我的 WebApi GET 操作中找不到某些内容时,我将返回一个 NotFound IHttpActionResult
。除了此响应,我还想发送自定义消息和/或异常消息(如果有)。当前 ApiController
的 NotFound()
方法不提供传递消息的重载。
有什么办法吗?或者我必须编写自己的自定义 IHttpActionResult
?
最佳答案
这是一个用简单消息返回 IHttpActionResult NotFound 的代码:
return Content(HttpStatusCode.NotFound, "Foo does not exist.");
关于c# - 如何返回带有错误消息或异常的 NotFound() IHttpActionResult?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139621/