我的 Web Api 在本地运行时(在 Release模式下)将返回以下格式的任何错误:
{
"Message": "An error has occurred.",
"ExceptionMessage": "No text specified",
"ExceptionType": "System.Exception",
"StackTrace": null
}
但是在部署/发布到 Azure VM 后,只剩下以下内容:
{
"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 上更详细,例如本地结果。
这可以实现吗?如果可以,如何实现?
我已经(暂时)删除了 <compilation xdt:Transform="RemoveAttributes(debug)" />
来自<system.web>
Web.Release.config 的一部分,然后重新部署,但这没有什么区别。
或者我使用了错误的方法/模式?
显然技术细节应该是有限的,但现在我们根本没有得到任何细节。
最佳答案
您可以尝试将以下内容添加到 Global.asax:
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
注意:我不建议您在生产环境中保留此设置。
关于azure - Azure 上的 Web Api 使用 'return InternalServerError(ex)' 未显示任何错误详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25430077/