Exception: System.AggregateException: 发生一个或多个错误。 ---> System.Threading.Tasks.TaskCanceledException: 已取消一个任务。
System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(System.Net.Http.HttpRequestMessage request,
System.Threading.CancellationToken cancellationToken) >
System.Net.Http.HttpMessageInvoker.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) >
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(System.Net.Http.HttpRequestMessage request,
System.Threading.CancellationToken cancellationToken) > System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start() >
System.Web.Http.Dispatcher.HttpControllerDispatcher+<SendAsync>d__1.MoveNext() >
System.Web.Http.Controllers.ActionFilterResult.ExecuteAsync() >
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start() >
System.Web.Http.Controllers.ActionFilterResult+<ExecuteAsync>d__2.MoveNext() >
System.Web.Http.Controllers.ApiControllerActionInvoker.InvokeActionAsyncCore(System.Web.Http.Controllers.HttpActionContext actionContext,
System.Threading.CancellationToken cancellationToken) > System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start() >
System.Web.Http.Controllers.ApiControllerActionInvoker+<InvokeActionAsyncCore>d__0.MoveNext() >
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext controllerContext,
System.Collections.Generic.IDictionary`2[System.String,System.Object] arguments, System.Threading.CancellationToken cancellationToken) >
System.Web.Http.Controllers.ReflectedHttpActionDescriptor+ActionExecutor+<>c__DisplayClass12.<GetExecutor>b__8(System.Object instance, System.Object[] methodParameters) >
?.lambda_method(System.Runtime.CompilerServices.Closure , System.Object , System.Object[] ) >
今天查看网站日志时,发现不少这种错误信息。
访问一个页面时,AJAX 请求 ASP.NET Web API 。多次点击刷新,出错。
原因:页面加载 =》 ajax 触发 web api =》 页面刷新 =》web api 的任务被取消 ; web api 是异步编程, 任务取消时,会触发 AggregateException 导常。
日志记录时,遇到 AggregateException 时,直接忽略。