How do I return NotFound() IHttpActionResult with an error message or exception?

前端 未结 10 2096
情书的邮戳
情书的邮戳 2020-12-02 07:18

I am returning a NotFound IHttpActionResult, when something is not found in my WebApi GET action. Along with this response, I want to send a custom message and/

10条回答
  •  隐瞒了意图╮
    2020-12-02 07:52

    Here's a one-liner for returning a IHttpActionResult NotFound with a simple message:

    return Content(HttpStatusCode.NotFound, "Foo does not exist.");
    

提交回复
热议问题