【发布时间】:2020-01-07 01:18:51
【问题描述】:
我有基于 ASP.NET Core 2.2 的 API,我不想从处理请求的公共方法返回结果,而是从内部方法返回结果。
public class UsersController : MainController
{
[HttpGet("{id:int}")]
public IActionResult Get(int id)
{
var value = GetSomeValue();
}
private string GetSomeValue()
{
// and here I want to return result to user not even returning result to calling method `Get`
return "";
}
}
我可以通过HttpContext.Response.StatusCode 将状态代码设置为响应,并且我知道如何为响应设置正文,但我也不知道是否可以从GetSomeValue 方法向用户返回响应。可能以某种方式使用HttpContext?
【问题讨论】:
标签: asp.net-core