正如标题所说,从GET请求到IQueryable操作,我收到了500个内部服务器错误。错误的正文为空。该错误发生在我的操作返回结果之后。
我使用ASP.NET Web API RC。
如何获取错误堆栈跟踪信息?
发布于 2012-06-13 04:59:23
发布RC后,此问题已修复,除了500内部服务器错误外,您还将获得错误详细信息。(此问题仅针对Web主机方案进行了修复)。
您可以执行以下操作来获取格式化程序的WriteToStream方法期间可能发生的实际异常的详细信息。
ObjectContent<IEnumerable<Product>> responseContent = new ObjectContent<IEnumerable<Product>>(db.Products.Include(p => p.ProductSubcategory).AsEnumerable(), new XmlMediaTypeFormatter()); // change the formatters accordingly
MemoryStream ms = new MemoryStream();
// This line would cause the formatter's WriteToStream method to be invoked.
// Any exceptions during WriteToStream would be thrown as part of this call
responseContent.CopyToAsync(ms).Wait();
发布于 2012-07-04 04:05:10
我遇到了同样的问题。我发现Kiran Challa's response有助于在我的操作之外抛出实际的异常。
为了解决我的问题,setting the ProxyCreationEnabled property of my context to false让我走得更远。
在我的场景中,我的下一个异常是由于我的模型中的循环引用。清理之后,幻影500响应就消失了。如果你还没有解决这个问题,祝你好运!
发布于 2015-12-18 17:12:22
在我的例子中,一个看似简单的路由缺陷导致了这个问题:在我的Api控制器中有另一个具有相同签名(而不是名称)的HttpPost。默认路由没有解决名称差异,并且ServiceError 500是它在到达任一Api功能之前给出的响应。解决方案:更改默认路由或签名,然后重试。
下面是我的RouteConfig.cs,它非常适合标准的WebApi2用法:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Default is required in any case.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
https://stackoverflow.com/questions/10944938
复制相似问题