I have the following action in the server:
[HttpPost]
public JsonResult SearchContracts(SearchViewModel vm)
{
List<string> errors;
if (IsValid(vm, out errors))
{
return Json(service.Search(vm), JsonRequestBehavior.AllowGet);
}
else
{
HttpContext.Response.StatusCode = 500;
return Json(new { Errors = errors }, JsonRequestBehavior.AllowGet);
}
}
Locally, it works great. When the request is not valid, it returns a JSON with the errors and the response has a 500
for the HTTP status code.
When deployed, instead of the JSON described, IIS is returning me this famed error page.
Here is the web.config
with the detail for the customErrors
section:
<customErrors mode="Off" defaultRedirect="~/error.htm">
<error statusCode="404" redirect="~/errorhandling/pagenotfound" />
</customErrors>
I tried turning it to On
but neither worked.
Where should I change to stop recieving that ugly error page instead of my beauty JSON?
Edit:
I changed the status code to 400
, now I am getting the text Bad Request
as a response, instead of the JSON: