"Server cannot append header after HTTP headers have been sent" after upgrading from 1.6 to 1.7.1

Topics: General, Troubleshooting
Nov 12, 2013 at 12:50 PM
We have an Orchard solution currently running on version 1.6 in Azure.

After upgrading to Orchard 1.7.1, we are intermittently seeing the error message "Server cannot append header after HTTP headers have been sent.". I know what this error means, but what I can't figure out is what has changed between version 1.6 to 1.7.1 to introduce this issue.

I should mention that we have a few custom modules in this solution and that I am not seeing this issue from a clean download of 1.7.1. Additionally- I can't replicate it locally; this error only seems to happen when running in Azure (which is making the source of the exception tricky to track down).

I'm not asking for anyone to fix this for me, rather if anyone knows of something that could have changed between these two versions that could have caused this. I'm just looking for a starting point to investigate.

The exception is thrown intermittently when logging in, but 100% of the time when logging out.

Stack trace is:
[HttpException (0x80004005): Server cannot append header after HTTP headers have been sent.]
System.Web.HttpResponse.AppendHeader(String name, String value) +718
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +244
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +263
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +714
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +40
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) +42
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1799
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +3300
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +1536
Nov 12, 2013 at 5:04 PM
So I've tracked down the cause of this-

We had an action filter that appended some custom headers to the response. Unfortunately, the headers were being appended in the OnResultExecutED method as opposed to the OnResultExecutING method. Makes sense I suppose, although seems a bit weird that 1.6 didn't have an issue with it, yet 1.7.1 did.