locked
Error :Session state has created a session id, but cannot save it because the response was already flushed by the application. RRS feed

  • Question

  • User1564952282 posted

    Hello, we have a website that was developed under ASP.NET 1.1 and now we want to run it under ASP.NET 2.0. Since we cannot access the original code we placed it in a separate Application Pool and tested the site. Apparently all is oke, however every now and then the following problem:

     Exception message: Session state has created a session id, but cannot save it because the response was already flushed by the application.

     
    I researched the internet and found some possible solutions. One of them is not using Response.Flush(), but since we cannot access the source that isn't option.

     

    Is there any other way to overcome this, please help us out!!

     

    Greetings,

    Jan
     

     

     

    Monday, November 20, 2006 4:17 AM

Answers

  • User-1466702846 posted

    That happens because sometimes (depending on the web.config configuration) the SessionID is not set in the cookie when Session_Srtart event executes in the global asax.

    You encounter this error because at somepoint in the pagelifecycle a variable is set in the session. After the request ends, ASP.NET tries to set the SessionID too, but if the Request was flused (eg. this can be done by Response.Write or AJAX itself flushes the response) this exception will be thrown.

     A simple fix would be (in the global.asax file):

     void Session_Start(object sender, EventArgs e) 
        {
    	// Code that runs when a new session is started
    
    	//Ensure SessionID in order to prevent the folloing exception
    	//when the Application Pool Recycles
    	//[HttpException]: Session state has created a session id, but cannot 
    	//				   save it because the response was already flushed by 
    	string sessionId = Session.SessionID;
        }
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2007 7:51 AM

All replies

  • User988234007 posted
    You find a solution for this yet?  I'm getting this too, and I don't have a single flush statement in my projects.
    Monday, November 27, 2006 11:38 AM
  • User1564952282 posted
    No unfortunately no one came up with a solution. For now I i use this code within the 1.1 framwork where it works oke!!
    Monday, December 18, 2006 1:53 PM
  • User-1466702846 posted

    That happens because sometimes (depending on the web.config configuration) the SessionID is not set in the cookie when Session_Srtart event executes in the global asax.

    You encounter this error because at somepoint in the pagelifecycle a variable is set in the session. After the request ends, ASP.NET tries to set the SessionID too, but if the Request was flused (eg. this can be done by Response.Write or AJAX itself flushes the response) this exception will be thrown.

     A simple fix would be (in the global.asax file):

     void Session_Start(object sender, EventArgs e) 
        {
    	// Code that runs when a new session is started
    
    	//Ensure SessionID in order to prevent the folloing exception
    	//when the Application Pool Recycles
    	//[HttpException]: Session state has created a session id, but cannot 
    	//				   save it because the response was already flushed by 
    	string sessionId = Session.SessionID;
        }
     
    Tuesday, February 13, 2007 7:51 AM
  • User-1466702846 posted

    That happens because sometimes (depending on the web.config configuration) the SessionID is not set in the cookie when Session_Srtart event executes in the global asax.

    You encounter this error because at somepoint in the pagelifecycle a variable is set in the session. After the request ends, ASP.NET tries to set the SessionID too, but if the Request was flused (eg. this can be done by Response.Write or AJAX itself flushes the response) this exception will be thrown.

     A simple fix would be (in the global.asax file):

     void Session_Start(object sender, EventArgs e) 
        {
    	// Code that runs when a new session is started
    
    	//Ensure SessionID in order to prevent the folloing exception
    	//when the Application Pool Recycles
    	//[HttpException]: Session state has created a session id, but cannot 
    	//				   save it because the response was already flushed by 
    	string sessionId = Session.SessionID;
        }
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2007 7:51 AM
  • User-1846049322 posted

     That was interesting. I tried your Session_Start solution however...<o:p></o:p>

    When i ran it, it just started an endless loop trying to call the same page over and over until i stopped it.<o:p></o:p>

    Thanks for the suggestion, anything is helpful<o:p></o:p>

    Wednesday, December 22, 2010 4:06 PM