Get in Touch
Thank you for your interest! Please fill out the form below if you would like to work together.

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form

Server cannot append cookies after HTTP headers have been sent.

Gavin Stevens
Jul 15, 2018

I caused this error in my web application somehow: "Server cannot append cookies after HTTP headers have been sent."  Seems to be a timing issue.  I can't recall any changes I've recently made that would have caused this error. If I google this error, it doesn't return much, a bunch of partially matched results that are similar: "Server cannot append header after HTTP headers have been sent" So, it seems like timing.. Like the Response object is already being redirected and can no longer be written to.


The response object: "IsRequestBeingRedirected" is false however.  So, thanks to the power of source control, I'm going to pull an earlier version of my application and see if I can find when this error got introduced.  Who says time travel doesn't exist! While waiting for the code to pull an older version, I googled around a bit, found an older topic where someone said:  " We were adding Cookies to the Response during an Ajax call and now the error went away." So, this may be a lead, I did change some .ajax calls recently, maybe that is the cause. Maybe its Request-> Process Page -> Return to Client -> Client invokes ajax -> ajax tries to write to Response. So, I went back in time.  I took my Main Source Branch and created a new branch called BugTest1031. I branched the code from a changeset from the morning on 10/31 which was 3 days ago.  (I didn't have this problem then) After branching the source, the code works again!  While this is great, I need to compare it to my current version, so whats the best way? I plan to merge into my branch each change set since the 1031 branch.  This way I can identify exactly which version of the application caused the problem. So, I merged in the next 4 changesets, compiled, tested it, still works...  Next 4 changesets..  and there we go, now the error is produced.  So what changed in these 4 changesets?  I had added some data to the ViewBag to pass to the Page View from the Controller.  I didnt want to modify the Model, so added it to the viewbag.  This apparently caused the problem! In Controller I had:             

Gavin Stevens

Recent Blog Posts

Lets Work Together
Contact Me