title: What's causing “Session state has created a session id, but cannot save it because the response was already flushed by the application.”
body: <p>I'm getting this fault intermittently. </p>
  
  <p>I found this link which summarises fairly well what I was able to find on the Google:
  <a href="http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but-cannot-save-it-because-the-response-was-already-flushed-by-the-application/" rel="noreferrer">http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but-cannot-save-it-because-the-response-was-already-flushed-by-the-application/</a></p>
  
  <p>Basically it says you can try setting the web config setting DisplayWhenNewSession, or try kicking the session state thing into life by getting the Session.SessionID in the Session_OnStart.</p>
  
  <p>But does anyone:</p>
  
  <p>a) have an explanation for this</p>
  
  <p>or even better, b) have a tried and tested fix</p>
  
  <p>I realise that I can't flush the response after doing anything that would affect the http response header. If I did this it would cause an error <em>every time</em> but this is intermittent. The SessionID should surely be created by ASP.NET at the beginning of the page response automatically, before anything in the ASPX page or the Page_Load (which is where all my flushes are called).</p>
  
  <p><strong>Update:</strong> 
  On reflection I realise this is happening when streaming a file down to the browser. Most of the browsers are actually search engine bots. I can recreate this error by starting a download and then closing the browser, so presumably the browsers are not waiting for the download to complete before cancelling the download operation. I have also seen this on other, normal pages, but 99% of the time it is download pages.</p>