0

我在设置100响应状态码时遇到问题。我尝试了以下方法:

HttpContext.Response.StatusCode = 100;

但它不起作用,服务器拒绝回答。有没有人遇到过类似的问题?

4

1 回答 1

0

尝试使用与 Web API 相关的操作结果之一Controller来获得所需的响应。

//returns a response with specified status code
public IActionResult StatusCodeActionResult() {
    return StatusCode(100); //<-- StatusCodeResult
}

//returns a response with specified status code along with an object
public IActionResult StatusCodeWithObjectResult() {
    return StatusCode(100, new { Data = "HelloWorld" }); //<-- ObjectResult
}
于 2018-01-29T12:52:17.510 回答