【问题标题】:Asp.net Web API returns non-descriptive error 500Asp.net Web API 返回非描述性错误 500
【发布时间】:2012-04-20 09:42:02
【问题描述】:

在我的设置中,如果我的 Web API 请求出现任何问题,我会收到错误 500。

以这个简单的代码为例。

public IQueryable<Article> Get(){
    throw new Exception("error");
    return db.Articles; //yeah i know.. unreachable, not the point
}

我的期望(以及在常规 MVC 控制器中会发生什么):

我得到了什么(在 Web API 中):

我的网络配置:

<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5">

//under webserver
<httpErrors errorMode="detailed"/>

应用程序池在集成模式下运行 4.0。已启用 32 位应用程序。

如何在浏览器中显示错误?或者至少在调试期间?

【问题讨论】:

标签: c# iis-7.5 asp.net-web-api


【解决方案1】:

遇到了同样的问题。

为我添加

    GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

在WebApiConfig Register 方法中有所帮助。

之后,我得到了有关错误的详细信息。

这里有更多关于MSDN的信息

【讨论】:

    【解决方案2】:

    如果它是 WCF Web 服务,则必须将 ServiceBehavior 属性的 IncludeExceptionDetailInFaults 标志设置为 true,才能以所需的方式显示错误。

    【讨论】:

    • 因为即使在 1 年后也没有人给他正确的答案..甚至你也没有。
    猜你喜欢
    • 2012-06-12
    • 2018-10-04
    • 2017-10-28
    • 2021-09-24
    • 1970-01-01
    • 2017-01-17
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多