📜  ow-to-return-http-500-from-asp-net-core-rc2-web-api - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:23.530000             🧑  作者: Mango

代码示例1
From what I can see there are helper methods inside the ControllerBase class. Just use the StatusCode method:

[HttpPost]
public IActionResult Post([FromBody] string something)
{    
    //...
    try
    {
        DoSomething();
    }
    catch(Exception e)
    {
         LogException(e);
         return StatusCode(500);
    }
}
You may also use the StatusCode(int statusCode, object value) overload which also negotiates the content.