Jacob Parker
Jacob Parker

Reputation: 2556

ASP.NET+Azure 400 Bad Request doesn't return JSON data

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?

Upvotes: 31

Views: 8230

Answers (1)

dccollie
dccollie

Reputation: 818

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.

Upvotes: 70

Related Questions