您可以使用以下命令返回http状态代码和响应对象:
return Ok(responseObject);
return BadRequest(responseObject);
return NotFound(responseObject);
但是你想要返回自己的自定义http状态代码呢? 402,429,500,501等
答案 0 :(得分:3)
return StatusCode(402, responseObject);
return StatusCode(500, responseObject);
答案 1 :(得分:2)
Response.StatusCode = 500; // HttpStatusCode.
return responseObject;
OR
Response.StatusCode = StatusCodes.Status500InternalServerError; // HttpStatusCode.
return responseObject;