30
votes

There is an action in my ASP.NET MVC controller that returns JSON data with a 400 Bad Request when invalid parameters are passed to the action.

[HttpDelete]
public ActionResult RemoveObject(string id) {
    if(!Validate(id)) {

        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return Json(new { message = "Failed", description = "More details of failure" });
    }
}

This works perfectly running under IIS or with the development test server launched from Visual Studio. After the project has been deployed to Azure the 400 Bad Request comes back without the JSON data. The content type has changed to 'text/html' and 'Bad Request' for the message.

Why is the behavior different under Azure?

1

1 Answers

63
votes

Add the following entry to your 'web.config'.

<system.webServer>
  <httpErrors existingResponse="PassThrough"/>
</system.webServer>

This will allow HTTP errors to pass through un-molested.