Reputation: 1870
I want to return BadRequest
status and error message from my MVC controller:
public class TestController : System.Web.Mvc.Controller
{
public ActionResult Bad()
{
Response.StatusCode = 400;
return new JsonResult()
{
Data = new { Message = "Request is bad!" },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
}
It works when I launch application in IISExpress, the method returns response body:
{"Message":"Request is bad!"}
But when I deploy same site to IIS (ver. 8.5) the response body changed to:
Bad Request
Why this happen? Is there some settings that allows to keep response body when status is not 200?
Upvotes: 0
Views: 735
Reputation: 1870
I found two solutions:
existingResponse
to PassThrough
in httpErrorsUpvotes: 1