Tips that make life of a software engineer easier. Well, not exactly. Some posts are open questions that I haven't found an answer ... yet
Thursday, March 22, 2012
Monday, March 12, 2012
ASP.NET Exception: "Session state has created a session id, but cannot save it ..."
Symptom:
Cause:
Set Buffer to true is not a solution for me, because I will need to flush content to deliver real-time progress information.
Based on some understanding, a solution quickly came up with some Google search. Simply add the following line to Global.asax.cs > Session_Start, the problem is resolved.
string sessionID = Session.SessionID;
- Only happens for new session
- Exception Message:
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll Additional information: Session state has created a session id, but cannot save it because the response was already flushed by the application.
- Stack Trace:
Cause:
- I was able to narrow down the cause of this problem to setting page's Buffer="false"
- Reasoning would be that without buffering, all content are pushed to client immediately, and somehow, ASP.NET decided to set cookie at a very late stage where it can no longer write to HTTP header to set SessionID cookie
Set Buffer to true is not a solution for me, because I will need to flush content to deliver real-time progress information.
Based on some understanding, a solution quickly came up with some Google search. Simply add the following line to Global.asax.cs > Session_Start, the problem is resolved.
string sessionID = Session.SessionID;
Subscribe to:
Posts (Atom)