How to return HTTP 500 from ASP.NET Core RC2 Web Api?

The Solution to How to return HTTP 500 from ASP.NET Core RC2 Web Api? is


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.

~ Answered on 2016-06-13 15:30:24


Most Viewed Questions: