2012-06-27 110 views
4

我遇到WebAPI问题返回空500.WebAPI空500错误

这里是数据类。

public class Comment 
{ 
    public int Id { get; set; } 
    public string Content { get; set; } 
    public string Email { get; set; } 
    public bool IsAnonymous { get; set; } 

    public int ReviewId { get; set; } 
    public Review Review { get; set; } 
} 
public class Review 
{ 
    public int Id { get; set; } 
    public string Content { get; set; } 

    public int CategoryId { get; set; } 
    public string Topic { get; set; } 
    public string Email { get; set; } 
    public bool IsAnonymous { get; set; } 

    public virtual Category Category { get; set; } 
    public virtual ICollection<Comment> Comments { get; set; } 
} 

这里的代码来从ReviewRepository.cs

public Review Get(int id) 
{ 
    return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id); 
} 

而且从ReviewController.cs

public HttpResponseMessage Get(int id) 
{ 
    var category = _reviewRepository.Get(id); 
    if (category == null) 
    { 
     return Request.CreateResponse(HttpStatusCode.NotFound); 
    } 
    return Request.CreateResponse(HttpStatusCode.OK, category); 
} 

不管我做什么的代码,响应从/ API /评论回/ 1是500错误。调试时,所有加载的评论都是正确的。

我试过GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;,但这并没有帮助。我在这里亏本!

回答

0

我遇到了同样的问题。除了GlobalConfiguration策略之外,您可能还需要在web.config中包含以下内容。

<system.webServer> 
    <httpErrors existingResponse="PassThrough" /> 
</system.webServer> 
+0

不过没什么通过只是一个空洞的500 :( – jcreamer898

0

这可能是序列号为ICollection<Comment> CommentsCategory Category