odd*_*ddy 71 exception-handling asp.net-web-api
正如标题所说,我从GET请求到IQueryable操作有500个内部服务器错误.错误的主体是空的.我的操作返回结果后发生该错误.
我使用ASP.NET Web API RC.
如何获得该错误的堆栈跟踪?
Ste*_*r B 58
您可以尝试添加:
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy =
IncludeErrorDetailPolicy.Always;
Run Code Online (Sandbox Code Playgroud)
您Application_Start()在Global.asax.此解决方案适用于许多常见错误.
但是,如果您没有获得满意的信息,则应考虑编写l 异常过滤器并在全局注册.
这篇文章应该可以帮到你.您需要的核心是编写和注册以下内容:
public class NotImplExceptionFilter : ExceptionFilterAttribute {
public override void OnException(HttpActionExecutedContext context) {
if (context.Exception is NotImplementedException) {
context.Response = new HttpResponseMessage(HttpStatusCode.NotImplemented);
}
}
}
Run Code Online (Sandbox Code Playgroud)
发布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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
86290 次 |
| 最近记录: |