Visual Studio .NET - Session state has created a session id, but cannot save it because the response was already flushed by the application.

Asked By Gyan Singh on 12-Dec-06 02:10 AM

Hi all,

I m getting the following error:

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

I m using the code as below:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

ViewState("PageIndex") = 0

ViewState("PageCount") = 0

ViewState("SelChk") = ""

''Session("Bal") = 0.0

Context.Session.Add("Bal", 0.0)

''Context.Session("NoVar") = ""

Context.Session.Add("NoVar", "")

Context.Cache("TotalRows") = 0

Context.Session.Add("AccountHierarchy", "")

Response.Write("<html>")

Response.Write("<head>")

Response.Write("<body>")

Response.Write("<div ID='divStatus' CLASS='pleasewaithidden' NAME='divStatus' STYLE='position:absolute; width:750px; height:40px; z-index:1; left: 100px; top: 61px'>")

Response.Write("<center><table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td align=center >")

Response.Write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=230 height=61 id=OBJECT1>")

Response.Write("<param name=""movie"" value=""../Images/loader.swf""><param name=""quality"" value=""high"">")

Response.Write("<embed src=""../Images/loader.swf"" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" ")

Response.Write("type=""application/x-shockwave-flash"" width=230 height=61>")

Response.Write("</embed></object></td></tr></table></center></div>")

Response.Write("</body>")

Response.Write("</head>")

Response.Write("<script type=""text/javascript"">")

'CODE CHANGE FOR COLOR OF SCROLL BAR

Response.Write("document.body.style.scrollbarFaceColor = ""#31454C""")

Response.Write("</script>")

Response.Write("</html>")

Response.Flush()

hdFlag = "1"

End If

End Sub

Please help me out of this problem..

Thanks & Regards,

GD

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

K Pravin Kumar Reddy replied to Gyan Singh on 12-Dec-06 05:38 AM

1) If you get an Exception saying "Session state has created a session ID, but cannot save it because the response was already flushed by the application" then make sure you have set DisplayWhenNewSession to 'false'

http://www.codeproject.com/useritems/WebRequestPanel.asp

you lose session state when the application pool is recycled (unless you r using sql server to store your sessions, of course) if that is your problem, and it occurs frequently, then someone missconfigured your webserver as app. pool recycling can be regulated in IIS. i personally think that the error message received sounds like its the app_pool... just a guess, but i'd take a look at the iis settings... try putting the app in a seperate pool for testing, or regulate the recyle settings.

reference

http://www.eggheadcafe.com/community/aspnet/6/10008376/re.aspx