Asp.net Web API返回非描述性错误500 [英] Asp.net Web API returns non-descriptive error 500
本文介绍了Asp.net Web API返回非描述性错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的设置中,如果我的Web API请求有任何问题,则会出现错误500.
In my setup I get error 500 if anything goes wrong with my Web API request.
例如,具有以下简单代码.
For instance with this simple code.
public IQueryable<Article> Get(){
throw new Exception("error");
return db.Articles; //yeah i know.. unreachable, not the point
}
我所期望的(以及常规MVC控制器中会发生的事情):
What I expect(and what happens in a regular MVC controller):
我得到的(在Web API中):
What I get (in Web API):
我的网络配置:
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5">
//under webserver
<httpErrors errorMode="detailed"/>
应用程序池在集成模式下运行4.0.启用了32位应用程序.
The app pool is running 4.0 in integrated mode. 32-bit applications are enabled.
如何在浏览器中显示错误?还是至少在调试过程中?
How can I get the error to surface in the browser? Or at the very least during debugging?
推荐答案
出现相同的问题.
对我来说
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
帮助. in the 之后,我得到了有关该错误的详细信息. After that I got nice detailed info about the error. 有关
查看全文
Register
方法中的WebApiConfig
Register
method helped.