我正在寻找在.NET Core Web API控制器中正确返回带有HTTP状态码的JSON的方法。我曾经这样使用:
public IHttpActionResult GetResourceData()
{
return this.Content(HttpStatusCode.OK, new { response = "Hello"});
}
这是在一个4.6的MVC应用程序中,但现在使用.NET Core时我似乎没有这个IHttpActionResult
,我有ActionResult
并且像这样使用:
这是在一个4.6的MVC应用程序中,但现在使用.NET Core时我似乎没有这个IHttpActionResult
,我有ActionResult
并且像这样使用:
public ActionResult IsAuthenticated()
{
return Ok(Json("123"));
}
但是服务器的响应很奇怪,就像下面的图片:
我只想让 Web API 控制器像在 Web API 2 中那样返回带有 HTTP 状态码的 JSON。