diff --git a/src/Microsoft.AspNet.Diagnostics/ErrorHandlerMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/ErrorHandlerMiddleware.cs index 6696f62dbc..677e0e690a 100644 --- a/src/Microsoft.AspNet.Diagnostics/ErrorHandlerMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics/ErrorHandlerMiddleware.cs @@ -28,17 +28,15 @@ namespace Microsoft.AspNet.Diagnostics public async Task Invoke(HttpContext context) { - var responseStarted = false; try { - context.Response.OnSendingHeaders(state => responseStarted = true, null); await _next(context); } catch (Exception ex) { _logger.LogError("An unhandled exception has occurred: " + ex.Message, ex); // We can't do anything if the response has already started, just abort. - if (responseStarted) + if (context.Response.HasStarted) { _logger.LogWarning("The response has already started, the error handler will not be executed."); throw; diff --git a/src/Microsoft.AspNet.Diagnostics/StatusCodePagesMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/StatusCodePagesMiddleware.cs index 1057653ba4..9d339e38a5 100644 --- a/src/Microsoft.AspNet.Diagnostics/StatusCodePagesMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics/StatusCodePagesMiddleware.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Diagnostics } // Do nothing if a response body has already been provided. - if (context.Response.HeadersSent + if (context.Response.HasStarted || context.Response.StatusCode < 400 || context.Response.StatusCode >= 600 || context.Response.ContentLength.HasValue