从网页API方法返回的错误消息在非开发环境省略 [英] Error messages returned from Web API method are omitted in non-dev environment

查看:215
本文介绍了从网页API方法返回的错误消息在非开发环境省略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,其行为在当地和测试服务器上罚款的Web API控制器POST方法。如果一切顺利返回:

I have a Web API controller POST method that behaves fine locally and on the testing server. If everything goes well it returns:

new HttpResponseMessage( HttpStatusCode.Created )

如果出现错误,则返回:

If something goes wrong, it returns:

new HttpResponseMessage<IEnumerable<string>>( usefulMessages, HttpStatusCode.BadRequest );

问题是,当我提出到导致错误的测试服务器的请求,我得到了错误的请求code回来,但我从来没有看到的消息。如果我对我的本地机器完全一样的要求,我看到的消息。下面的输出是从我自己的工具:

The problem is that when I make a request to the testing server that results in an error, I get the bad request code back but I never see the messages. If I make the exact same request to my local machine, I do see the messages. The following outputs are from my own tool:

发送请求到我的本地机器上,我得到:

Sending a request to my local machine I get:

Status code: 400 (BadRequest)
Response data: ["Error message one", "Error message two"]

发送到测试服务器,我得到一个请求:

Sending a request to the testing server I get:

Status code: 400 (BadRequest)
Response data: Bad Request

这是正在运行的code是完全一样的。该数据库是相同的。一切是除了服务器请求提供服务的相同。我甚至有code到电子邮件自己的错误信息,所以我知道该服务器产生正确的错误信息和正确的行为。难道这是一个IIS的事情(像的customErrors的当量=仅限远程的Web API)?不仅是从响应数据省略了错误信息,一些发明了那句错误的请求就摆在那里吧。

The code that is running is exactly the same. The database is the same. Everything is the same except for the server servicing the request. I even have code to email myself the error messages so I know that the server is producing the correct error messages and behaving correctly. Could this be an IIS thing (like the equivalent of customErrors = RemoteOnly for Web API)? Not only are the error messages omitted from the response data, something invents the phrase "Bad Request" to put in there instead.

任何想法?谢谢你。

推荐答案

在看看<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.http.httpconfiguration.includeerrordetailpolicy(v=vs.108).aspx\"相对=nofollow>在此HttpConfiguration.IncludesErrorDetailPolicy MSDN帖子:

在您的Global.asax:

In your Global.asax:

var config = GlobalConfiguration.Configuration;
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

我已经使用这个配置属性来强制错误消息,包括细节。

I have used this configuration property to force error messages to include details.

这篇关于从网页API方法返回的错误消息在非开发环境省略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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