对于在不同环境中如何显示错误详细信息,ASP.NET Web API有一个单独的配置。
在你
HttpConfiguration
,有一个名为
IncludeErrorDetailPolicy
. 这是它可能的价值。
public enum IncludeErrorDetailPolicy
{
// Summary:
// Use the default behavior for the host environment. For ASP.NET hosting, usethe value from the customErrors element in the Web.config file.
// For self-hosting, use the value System.Web.Http.IncludeErrorDetailPolicy.LocalOnly.
Default = 0,
// Summary:
// Only include error details when responding to a local request.
LocalOnly = 1,
//
// Summary:
// Always include error details.
Always = 2,
//
// Summary:
// Never include error details.
Never = 3,
}
您可以配置如下:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCloudServiceGateway();
var config = new HttpConfiguration
{
IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always // Add this line to enable detail mode in release
};
WebApiConfig.Register(config);
app.UseWebApi(config);
}
}
有关更多详细信息,请参阅
thread
.
另外,你可以设置
<customErrors mode="Off"/>
,它指定禁用自定义错误。这个
detailed ASP.NET errors
显示给远程客户端和本地主机。