diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs index 5d3fa722d1..7dcec90f46 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs @@ -805,7 +805,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration return _readWebSocketsOperation; } - public abstract Task ProcessRequestAsync(); + public abstract Task ProcessRequestAsync(); public void OnStarting(Func callback, object state) { diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs index 9f08ff7a54..4fbd3b5956 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs @@ -19,9 +19,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration _application = application; } - public override async Task ProcessRequestAsync() + public override async Task ProcessRequestAsync() { var context = default(TContext); + var success = true; try { @@ -37,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration catch (Exception ex) { ReportApplicationError(ex); + success = false; } finally { @@ -61,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration // If the request was aborted and no response was sent, there's no // meaningful status code to log. StatusCode = 0; + success = false; } try @@ -71,6 +74,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration { // TODO Log this _applicationException = _applicationException ?? ex; + success = false; } finally { @@ -90,6 +94,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration await _readingTask; } } + return success; } } } diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs index e65afdfb0a..9260293613 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs @@ -74,10 +74,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration if (task.IsCompleted) { context.Dispose(); - return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE; + return ConvertRequestCompletionResults(task.Result); } - task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state), context); + task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state, t), context); return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING; } @@ -96,15 +96,21 @@ namespace Microsoft.AspNetCore.Server.IISIntegration return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING; } - private static void CompleteRequest(IISHttpContext context) + private static void CompleteRequest(IISHttpContext context, Task completedTask) { // Post completion after completing the request to resume the state machine - context.PostCompletion(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE); + context.PostCompletion(ConvertRequestCompletionResults(completedTask.Result)); // Dispose the context context.Dispose(); } + private static NativeMethods.REQUEST_NOTIFICATION_STATUS ConvertRequestCompletionResults(bool success) + { + return success ? NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE + : NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST; + } + private class IISContextFactory : IISContextFactory { private readonly IHttpApplication _application;