Which forces "session state to create a session identifier but cannot save it because the response has already been reset by the application."

I get this error intermittently.

I found this link that pretty well describes what I could find on Google: http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but- cannot-save-it-because-the-response-was-already-flushed-by-the-application /

This basically means that you can try setting the DisplayWhenNewSession web configuration or try to get started with the session state state by getting Session.SessionID in Session_OnStart.

But someone:

a) have an explanation for this

or even better, b) have a proven and corrected fix

I understand that I cannot clear the response after doing everything that will affect the HTTP response header. If I did this, it would cause an error every time, but it is intermittent. SessionID must be created by ASP.NET at the beginning of the response to the page automatically, before anything on the ASPX page or in Page_Load (where all my flash files are called).

Update: When reflected, I understand that this happens when streaming a file to a browser. Most browsers are search engine bots. I can recreate this error by starting the download and then closing the browser, so presumably the browsers did not wait for the download to complete before the download operation was canceled. I also saw this on other normal pages, but in 99% of cases it loads pages.

+61
session-state
May 25 '09 at a.m.
source share
5 answers

I have!

In the global.asax file, you do the following:

void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started string sessionId = Session.SessionID; } 

So simple. He works!

+63
Dec 27 '09 at 17:56
source share

This error appears if:

  • Application launch

  • You use Global.asax even if you do something in Session_Start / End events or not

  • Your app makes flush response too fast

  • You do not use a session before flush

It arises from session state when it tries to save sessionID on release:

 System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext context, String id, Boolean& redirected, Boolean& cookieAdded) System.Web.SessionState.SessionStateModule.CreateSessionId() System.Web.SessionState.SessionStateModule.DelayedGetSessionId() System.Web.SessionState.SessionStateModule.ReleaseStateGetSessionID() System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

I believe that having Global.asax forces the session identifier to be saved when the SessionStateModule is released (late?), Even if no session was used for the HttpSessionState when calling SessionID.

This is the reason string sessionId = Session.SessionID; avoids the problem.

I assume that it appears only when the application starts because of initialization behavior.

Solutions / Tricks :

  • Avoid flushing in Page_Load, as already mentioned

  • Deactivate session state on page (EnableSessionState)

  • Use SessionID trick before flush

  • Use Response.End () instead of .Flush () if you don't care about errors that may occur after your flash

+17
Mar 16 '10 at 12:02
source share

I believe that the problem here may be precisely that you are doing something to cause the page to Page_Load during Page_Load , which, according to the ASP.NET page, has a lifecycle overview long before the rendering stage.

Make sure that you never do anything that could cause the page to display until after the PreRender stage.

+6
May 25 '09 at 1:16
source share

Just faced with this problem, I decided to share my findings.

Configuring web.config DisplayWhenNewSession does not matter, as it only applies to one specific custom controller on Codeplex (sorry I lost the link).

Another suggestion seems to work by initializing the SessionId first. I delved into the code using Reflector and couldn't understand how this prevented the error here, but it certainly worked for us!

Like most people who seem to be encountering this error, we do not explicitly call Response.Flush () anywhere in the application. We also use MVC for recording.

+3
Oct. 15 '09 at 15:30
source share

I admit that this is very old, but I found another reason for the error, which may be applicable to others. If you use MVC (I used MVC 4 with .Net 4.0) and you set the pages so as not to buffer using the web.config element

 <pages buffer="false"> 

Then, if you are trying to insert data into the session object in your code, you may run the risk of getting this error if the page starts rendering before viewing your child or an action that accesses the session.

In such cases, you can correct the error by changing the buffer setting above to true. Also, move the session access code to the main view, and not to the child view / child view.

0
Oct 22 '14 at 10:12
source share



All Articles