Azure上的Web Api使用'return InternalServerError(ex)'不显示任何错误详细信息 [英] Web Api on Azure shows no error detail using 'return InternalServerError(ex)'
问题描述
我的Web Api在本地运行(以发布模式)时,将以这种格式返回任何错误:
My Web Api when run locally (in Release mode) will return any errors in this format:
{
"Message": "An error has occurred.",
"ExceptionMessage": "No text specified",
"ExceptionType": "System.Exception",
"StackTrace": null
}
但是在部署/发布到Azure VM之后,只有以下内容:
But after deployment/publish to an Azure VM, only this remains:
{
"Message": "An error has occurred."
}
API代码:
try
{
var msg = ...
new MessageService().SaveMessage(msg)); // <-- does some checks; may throw.
return Ok();
}
catch (Exception ex)
{
return InternalServerError(ex);
}
我希望在Azure上更详细,例如本地结果.br
可以实现吗?如果可以,如何实现?
我已经(临时)删除了< compilation xdt: Web.Release.config的
-deployed,但这没什么区别。< system.web>
部分中的Transform = RemoveAttributes(debug) />
还是我使用了错误的方法/模式?
显然应该限制技术细节,但是现在
I'd like it to be more detailed on Azure, like the local result.
Can this be achieved, and if so, how?
I already (temporarily) removed <compilation xdt:Transform="RemoveAttributes(debug)" />
from the <system.web>
part of Web.Release.config, and then re-deployed, but that made no difference.
Or am I using the wrong approach/pattern?
Obviously technical details should be limited, but right now we get no details at all.
推荐答案
您可以尝试将以下内容添加到Global.asax:
You could try adding the following to your Global.asax:
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
注意:我不建议您在生产环境中保持此设置。
Note: I wouldn't recommend that you keep this setting on in a production environment.
这篇关于Azure上的Web Api使用'return InternalServerError(ex)'不显示任何错误详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!