Mvc4 WepApi空响应时,非200 [英] Mvc4 WepApi Empty Response when non 200
本文介绍了Mvc4 WepApi空响应时,非200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当一个Action被调用并抛出一个特定的异常,我使用ExceptionFilterAttribute的错误转化为作为的HTTPStatus code.BadRequest不同的反应。这已在本地工作,但我们把它推到一台服务器,现在当我得到的错误请求我不明白的效应初探任何信息。我缺少什么?
When an Action is called and throws a specific exception, I use an ExceptionFilterAttribute that translate the error into a different response as HttpStatusCode.BadRequest. This has been working locally, but we pushed it to a server and now when I get the BadRequest I do not get any information in the reponse. What am I missing?
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
MyException ex = actionExecutedContext.Exception as MyException;
if (ex == null)
{
base.OnException(actionExecutedContext);
return;
}
IEnumerable<InfoItem> items = ex.Items.Select(i => new InfoItem
{
Property = i.PropertyName,
Message = i.ToString()
});
actionExecutedContext.Result = new HttpResponseMessage<IEnumerable<InfoItem>>(items, HttpStatusCode.BadRequest);
}
编辑:当我打的本地服务体是包括在内。看来问题是从远程机器打的服务时。
When I hit the service locally the body is included. It seems the problem is when hitting the service from a remote machine.
推荐答案
试试这个:
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy =
IncludeErrorDetailPolicy.Always
这篇关于Mvc4 WepApi空响应时,非200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文