Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 884
Jacob Parker Avatar asked Mar 20 '13 19:03

Jacob Parker


1 Answers

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.

like image 108
dccollie Avatar answered Oct 02 '22 09:10

dccollie