Asp.net Web API返回非描述性错误500

Mar*_*sen 35 c# iis-7.5 asp.net-web-api

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

例如,使用这个简单的代码.

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

我期望的(以及常规MVC控制器中发生的事情):

在此输入图像描述

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

在此输入图像描述 我的网页配置:

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

//under webserver
<httpErrors errorMode="detailed"/>
Run Code Online (Sandbox Code Playgroud)

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

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

Gau*_*wal 1

如果它是 WCF Web 服务,则必须将 ServiceBehavior 属性的 IncludeExceptionDetailInFaults 标志设置为 true,以便错误按照您想要的方式显示。

  • 因为即使一年后也没有人给他正确的答案……甚至你也没有。 (3认同)