ASP.NET + Azure的400错误的请求不返回JSON数据 [英] ASP.NET+Azure 400 Bad Request doesn't return JSON data

查看:140
本文介绍了ASP.NET + Azure的400错误的请求不返回JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在我的ASP.NET MVC控制器与无效时的参数传递给操作的400错误的请求返回JSON数据的操作。

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" });
    }
}

这工作在IIS下或从Visual Studio推出的开发测试服务器上运行完美。该项目已被部署到Azure的后400错误的请求回来没有JSON数据。内容类型已更改为text / html的',为信息错误的请求。

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.

为什么Azure的不同的行为?

Why is the behavior different under Azure?

推荐答案

将以下条目添加到您的web.config中。

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

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

这将允许HTTP错误通过联合国调戏。

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

这篇关于ASP.NET + Azure的400错误的请求不返回JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆