title: .net Session state has created a session id, but cannot save it because the response was already flushed by the application
body: <p>I have below in my global.asax <code>Session_Start</code></p>
  
  <pre><code>string myBrowser = Utils.SafeUserAgent(Request);
  foreach (string bannedbrowser in BrowserBan.BrowsersToBan)
  {
     if (myBrowser.IndexOf(bannedbrowser, StringComparison.OrdinalIgnoreCase) &gt; -1)
     {
         HttpContext.Current.Response.Redirect("/bannedBrowser.htm");
         Session.Abandon();
         break;
     }
  </code></pre>
  
  <p>It prevents transcoders accessing o my site. but every now and then i get an error saying</p>
  
  <pre><code>System.Web.HttpException: Session state has created a session id, but cannot
    save it because the response was already flushed by the application.
      at System.Web.SessionState.SessionIDManager.SaveSessionID(
        HttpContext context, String id, Boolean&amp; redirected, Boolean&amp; cookieAdded)
      at System.Web.SessionState.SessionStateModule.CreateSessionId()
      at System.Web.SessionState.SessionStateModule.DelayedGetSessionId()
      at System.Web.SessionState.SessionStateModule.ReleaseStateGetSessionID()
      at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
        EventArgs eventArgs)
      at System.Web.SessionState.SessionStateModule.OnEndRequest(Object source,
        EventArgs eventArgs)
      at System.Web.HttpApplication.SyncEventExecutionStep.System.Web
        .HttpApplication.IExecutionStep.Execute()
      at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
        Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>this only happens when I try to access it via (for example) Google Transcoder but I want to understand why it happens and how can I prevent it.</p>
  
  <p>I have to abandon session so that on refresh user agent would re-evaluated.</p>