【发布时间】:2015-07-08 07:55:09
【问题描述】:
虽然我的 if 子句在我的提琴手中执行,但我看到 http 错误 500 而不是 404,这是为什么呢?
public class GlobalExceptionHandler : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext context)
{
if (context.Exception is ResourceNotFoundException)
{
context.Request.CreateErrorResponse(HttpStatusCode.NotFound, context.Exception.Message);
}
else
{
base.Handle(context);
}
}
}
这是我在提琴手响应中得到的:
HTTP/1.1 500 Internal Server Error
Content-Length: 3945
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 08 Jul 2015 08:14:45 GMT
{"Message":"An error has occurred.","ExceptionMessage":"The Resource could not be found!","ExceptionType":"ErpApplicationEndpoints.ResourceNotFoundException","StackTrace":" at ... Removed for clarity...
【问题讨论】:
-
您的自定义处理程序正在执行?
-
是的,就像我写的那样执行 if 子句!
-
我用提琴手响应更新了我的问题。
标签: c# asp.net-web-api asp.net-web-api2