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

前端 未结 8 2459
忘掉有多难
忘掉有多难 2020-12-04 17:01

Back in RC1, I would do this:

[HttpPost]
public IActionResult Post([FromBody]string something)
{    
    try{
        // ...
    }
    catch(Exception e)
            


        
8条回答
  •  余生分开走
    2020-12-04 17:44

    When you want to return a JSON response in MVC .Net Core You can also use:

    Response.StatusCode = (int)HttpStatusCode.InternalServerError;//Equals to HTTPResponse 500
    return Json(new { responseText = "my error" });
    

    This will return both JSON result and HTTPStatus. I use it for returning results to jQuery.ajax().

提交回复
热议问题