客户端已断开连接

我在WebAPI的日志中收到以下错误

System.Web.HttpException(0x800703E3):客户端已断开连接。 在System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult)处于System.Threading.Tasks.TaskFactory的System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult)1.FromAsyncTrimPromise 1.Complete(TInstance thisRef,Func 3 endMethod,IAsyncResult asyncResult) ,Boolean requiresSynchronization)—抛出exception的前一个位置的堆栈跟踪结束—在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处System.IO.StreamReader.d__97.MoveNext()—抛出exception的前一个位置的堆栈跟踪结束—在System.Runtime.CompilerServices.TaskAwaiter的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处System.IO.StreamReader.d__62.MoveNext()中的.HandleNonSuccessAndDebuggerNotification(任务任务)—从抛出exception的上一个位置开始的堆栈跟踪结束—在System.Runtime 位于Microsoft.Owin.OwinRequest.d__0.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)—抛出exception的上一个位置的堆栈跟踪结束—在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__22.MoveNext()—从抛出exception的先前位置开始的堆栈跟踪结束—在Microsoft.Owin.Security.OAuth的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处.OAuthAuthorizationServerHandler.d__0.MoveNext()—抛出exception的前一个位置的堆栈跟踪结束—在System.Runtime.CompilerServices.TaskAwaiter.Throw Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware 1.d__0.MoveNext()中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的ForSuonSuccess(任务任务)—从抛出exception的上一个位置开始的堆栈跟踪结束—在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于D:\ UAT中的Web.API.Middleware.OwinMiddleware.d__1.MoveNext() \ Web.API \ Middleware \ OwinMiddleware.cs:第49行

如何通过exceptionfilter处理和忽略这些exception? 为什么会出现此错误,如何重现? 我想捕获并忽略The client disconnected但不是所有HttpException

我看到了类似的问题,但我怎么能在exceptionfilter中做到这一点?

您可以忽略这些exception。

例外情况说明问题是:“客户端已断开连接”。 这意味着客户端发起了一个请求,但在它忘记阅读所有响应之前就断开了连接。

可能存在多种原因,但是(除非您的服务器端有一个狡猾的互联网连接),这几乎肯定是客户端的问题。 我经常看到这些,大多数似乎与机器人有关。 所以我把它们过滤掉然后忽略它们。

 try { // Open Connection // Do stuff } catch (HttpException ex) { // Log it? // Ignore it? // Do what you want with it? } finally { // Close connection }