Page view counter

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

Last post 02-13-2007 7:51 AM by softer. 4 replies.

Sort Posts:

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

    11-20-2006, 4:17 AM
    • Loading...
    • doolaard
    • Joined on 02-01-2006, 9:20 AM
    • Posts 16
    • Points 31

    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
     

     

     

    Greetings

    Jan Pieters
  • Re: Error :Session state has created a session id, but cannot save it because the response was already flushed by the application.

    11-27-2006, 11:38 AM
    • Loading...
    • CTGuy67
    • Joined on 06-24-2002, 7:16 AM
    • Posts 44
    • Points 99
    You find a solution for this yet?  I'm getting this too, and I don't have a single flush statement in my projects.
  • Re: Error :Session state has created a session id, but cannot save it because the response was already flushed by the application.

    12-18-2006, 1:53 PM
    • Loading...
    • doolaard
    • Joined on 02-01-2006, 9:20 AM
    • Posts 16
    • Points 31
    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!!
    Greetings

    Jan Pieters
  • Re: Error :Session state has created a session id, but cannot save it because the response was already flushed by the application.

    02-13-2007, 7:51 AM
    • Loading...
    • softer
    • Joined on 08-07-2006, 7:07 PM
    • Posts 13
    • Points 52

    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;
        }
     
  • Re: Error :Session state has created a session id, but cannot save it because the response was already flushed by the application.

    02-13-2007, 7:51 AM
    Answer
    • Loading...
    • softer
    • Joined on 08-07-2006, 7:07 PM
    • Posts 13
    • Points 52

    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;
        }
     
Page 1 of 1 (5 items)