【问题标题】:Incorrect response from an MVC app via an angular http post来自 MVC 应用程序通过角度 http 帖子的不正确响应
【发布时间】:2015-05-07 22:13:45
【问题描述】:

我有一个使用 Angular 在 Windows Server 2008 R2 上的 IIS 下运行的应用程序,带有 asp.net MVC 后端。

如果服务器发生错误,要返回错误数据,我执行以下操作:

Response.StatusCode = (int)HttpStatusCode.InternalServerError;  
return Json(response);

效果是一个JSON包被发回给angular调用者,错误处理程序被调用接收JSON包

this.http.post(workUrl, selezione)
.success((数据:SettoriProgettoResponse,状态)=> {
deferred.resolve(数据);
}).error((error: string[]) => {
deferred.reject(错误);
});

由于某种原因,过去几天 IIS 停止发回 JSON,而是发送标准 IIS 错误页面。

如何恢复之前的行为?

【问题讨论】:

  • 你能添加你的代码吗..你是怎么做的电话后
  • 我刚刚添加了完整的客户端代码,服务器端设置状态代码并返回 json 有效负载,客户端调用 .error 正确接收 json 有效负载。现在我收到了 IIS 错误页面的 html

标签: asp.net-mvc angularjs iis


【解决方案1】:

我在这里找到了解决问题的方法。

https://serverfault.com/questions/123729/iis-is-overriding-my-response-content-if-i-manually-set-the-response-statuscode

将此添加到 web.config

<system.webServer>
    <httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough"/>
    .... snipped other IIS relevant elements ... 
</system.webServer>

程序重新启动以按预期工作。
老实说,我不明白为什么没有这个设置到目前为止工作得很好,但现在看起来还可以。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2016-01-18
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多