ASP.NET Web API: Non-descriptive 500 Internal Server Error

前端 未结 10 1241
难免孤独
难免孤独 2020-12-07 16:08

As title says, I’ve got 500 Internal Server Error from GET request to an IQueryable action. The body of the error is empty. That error happens after my action returns result

10条回答
  •  执念已碎
    2020-12-07 16:54

    You can try adding:

    GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = 
        IncludeErrorDetailPolicy.Always;
    

    to your Application_Start() in the Global.asax. This solution works for many of the common errors.

    If, however, you aren't getting satisfactory information you should consider writing an l Exception Filter and registering it globally.

    This article should get you started. The core of what you need is to write & register something like:

    public class NotImplExceptionFilter : ExceptionFilterAttribute {
      public override void OnException(HttpActionExecutedContext context) {
         if (context.Exception is NotImplementedException) {
           context.Response = new HttpResponseMessage(HttpStatusCode.NotImplemented);
        }
      }
    }
    

提交回复
热议问题