azure - Azure 上的 Web Api 使用 'return InternalServerError(ex)' 未显示任何错误详细信息

标签 azure asp.net-web-api exception

我的 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/

相关文章:

java - 使用 JMS 安排 Azure 服务总线的消息

Azure 搜索在索引器运行后不会删除数据

c# - 如何解析 MultipartFormDataContent

java - 我正在尝试使用 Flowlayout 将 JPanel 添加到 JFrame,但仍然出现异常。我做错了什么?

Android 对话框调用目标异常

.net - 在进程关闭期间处理 ObjectDisposedException 和类似异常?

azure - 是否有 powershell 命令可以将 ipRules 添加到 azure 中的 CosmosDB?

c# - 在 Windows Azure 中处理联合身份验证中的注销

c# - 健康检查,ASP.NET Web API

c# - 指定的资源名称包含无效字符 即使 Blob 名称有效,为 Blob 生成 SAS url 时也会出错