即使在将 IncludeErrorDetailPolicy 设置为 Always 之后,也不会显示内部服务器错误 [500] 的详细信息

Details are not shown for Internal Server Error [500] even after setting the IncludeErrorDetailPolicy to Always

即使在 IncludeErrorDetailPolicyAlways

之后,我也没有看到错误详细信息

我在 Startup.cs 中有以下代码。

GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always

还有什么需要我做的吗?我可以在我的本地机器上获得完整的错误信息,但部署后在DEV服务器上却没有。

我登录到服务器并将 customError 模式设置为 "On"。此外,我将 httpErrors 设置为 "Detailed"。

<system.web>    
    <customErrors mode="On"/>
</system.web>

<system.webServer>    
    <httpErrors errorMode="Detailed"/>
</system.webServer>

经过这些更改后它也没有显示。在 IIS 中还有什么需要做的吗?

首先这不是一个答案。这是一个解决方法:

我从 Startup.cs

中删除了以下代码
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always

在 system.webServer 部分的 web.config 中添加了以下内容:

<httpErrors existingResponse="PassThrough" errorMode="Detailed" />

此外,我使用 ResponseMessage(HttpResponseMessage) 而不是 InternalServerError(Exception),如下所示:

private IHttpActionResult CustomHttpActionResult(string message)
{
   return ResponseMessage(new HttpResponseMessage
   {
      Content = new StringContent(message),
      StatusCode = HttpStatusCode.InternalServerError
   });
}