I've been playing with a small sample that shows how to do ajax style progress bars for long running tasks on the server and found a really strange problem that I hope someone can explain to me.
The source is here if anyone wants to play.
The idea is that when an update panel is posted back to the server I hook into this via the PageRequestManager BeginRequest and start a second callback going that can query the state of the original task.
This all works fine until you add a Global.ascx file to the project. At this point all the out of band callbacks that are meant to update the progress bar seem to be defered until after the first callback completes.
To see what I mean, grab the sample above run it then 'add a new item->Global Application Class' and run it again and the progress bar will fail to update. If you put a break point on GetCurrentStatus in UpdateProgressPage class you see that all the request
come in after the first callback completes!
Can anyone can explain this to me, I'm at a loss!!
BTW i've only tried this on two machines so far, I'd be intreasted to know if anyone else has the problem.
Thanks,
Stephen.
-
-
Well it's the Session_Start event that breaks it, still no idea why!
-
So I was watching what was going on with fidller and it seems that the second callback is made in a timely manner, but is blocked at the server until the first postback completes....
-
I have the same issue. Did you find a fix to the problem?
-
Cut from the notes of support call I had with MS.
-------------------------------------------------------------
Sessionstate "serializes" the requests...When you have UpdatePanels and simulatuosly use direct async callbacks on the client, these callbacks get serlized.
That is also the asnyc callbacks that may access SessionState are serliazed.
The workaround is to set the "EnableSessionState" property to "False" for the pages that need to both call pagemethods and implement UpdatePanels. But there is a tradeoffs, in that as soon as different access SessionState, serialization takes place:
"... When sessions are enabled ( by default), each request would lock onto the session state, hence only one request with the same session_id is processed at a time.
In the sample, session is enabled but not used. Hence session_id is not generated, and there is no contention for session state in subsequent calls. However when global.asax is added , Session_Start handler is defined. This has a sideeffect of session_id being added to the response, and corresponding state object being created ( the purpose of Session_start event is to let application initialize the session state.) which would cause only request per user to be processed at a time.
Now the sample makes async pagemethod calls while waiting for a partial postback ( async postback from update panel) to finish. When global.asax is defined all the pagemethods calls would be blocked on session state. The lock on session_state would be held by the partial postback request ( which sleeps for some time). Hence none of pagemethod calls are processed till the partial postback is completed. This is why progress bar never appears, as by the time progress value is returned back, the partial postback is already completed.
The work around for this is to put EnableSessionState=”Off” or EnableSessionState=”Readonly” in the Page directive. If only one of the page codebehind needs write to session, one could move the pagemethod to a seperate webservice. Unfortunately if both Page codebehind as well as page method code need to write to session state, only one request can be processed at a time...."
-
thank you very, very, very, very much !!!!

Federico -
Big thanks, i wasted f..n day to find whats wrong with PageMethods. To be honest MS could mentiond about such behaviour in ajax docs. I would save some time.
-
Hi,PerfectPhase said:Cut from the notes of support call I had with MS.
-------------------------------------------------------------
Sessionstate "serializes" the requests...When you have UpdatePanels and simulatuosly use direct async callbacks on the client, these callbacks get serlized.
That is also the asnyc callbacks that may access SessionState are serliazed.
The workaround is to set the "EnableSessionState" property to "False" for the pages that need to both call pagemethods and implement UpdatePanels. But there is a tradeoffs, in that as soon as different access SessionState, serialization takes place:
"... When sessions are enabled ( by default), each request would lock onto the session state, hence only one request with the same session_id is processed at a time.
In the sample, session is enabled but not used. Hence session_id is not generated, and there is no contention for session state in subsequent calls. However when global.asax is added , Session_Start handler is defined. This has a sideeffect of session_id being added to the response, and corresponding state object being created ( the purpose of Session_start event is to let application initialize the session state.) which would cause only request per user to be processed at a time.
Now the sample makes async pagemethod calls while waiting for a partial postback ( async postback from update panel) to finish. When global.asax is defined all the pagemethods calls would be blocked on session state. The lock on session_state would be held by the partial postback request ( which sleeps for some time). Hence none of pagemethod calls are processed till the partial postback is completed. This is why progress bar never appears, as by the time progress value is returned back, the partial postback is already completed.
The work around for this is to put EnableSessionState=”Off” or EnableSessionState=”Readonly” in the Page directive. If only one of the page codebehind needs write to session, one could move the pagemethod to a seperate webservice. Unfortunately if both Page codebehind as well as page method code need to write to session state, only one request can be processed at a time...."
Do we have any fix from microsoft? or anybody konws workaround.
Please let me know. I have the same issue.
Thanks,
DAC -
Hi,DAC said:
Hi,PerfectPhase said:*snip*
Do we have any fix from microsoft? or anybody konws workaround.
Please let me know. I have the same issue.
Thanks,
DAC
In my case I see that there are some limitation for the threads to fire async. I can see in IE 2 threads are firing async where as same page in safari fires 4 threads async at one time.
does anyone has the same issue?
--DAC -
DAC said:
Hi,DAC said:*snip*
In my case I see that there are some limitation for the threads to fire async. I can see in IE 2 threads are firing async where as same page in safari fires 4 threads async at one time.
does anyone has the same issue?
--DACHi !
Although, this thread is stone-old, may be, it is read. I am struggling with the same problem, which hinders me to use WCF, hosted by IIS. There seems to be no way to configure the session-mode with WCF.
A normal page can have "EnableSessionState="readonly", WCF not. But I need the session and a readonly access would be enough. But you cannot configure it with WCF. The same with webservices [asmx]. I tried to compile both with the interface "IReadOnlySessionState".
But it does not help. This lows down many of my ajax requests and I ask me, if I have to change the service side stack - to apache or soemthing java based. Don't know. The ajax performance is very, very poor!
Any help would be great!
br--mabra
-
mabra said:DAC said:*snip*
Hi !
Although, this thread is stone-old, may be, it is read. I am struggling with the same problem, which hinders me to use WCF, hosted by IIS. There seems to be no way to configure the session-mode with WCF.
A normal page can have "EnableSessionState="readonly", WCF not. But I need the session and a readonly access would be enough. But you cannot configure it with WCF. The same with webservices [asmx]. I tried to compile both with the interface "IReadOnlySessionState".
But it does not help. This lows down many of my ajax requests and I ask me, if I have to change the service side stack - to apache or soemthing java based. Don't know. The ajax performance is very, very poor!
Any help would be great!
br--mabra
mabra: in general web services should *ALWAYS* be state-less, there are many reasons for this.
but what does WCF have to do with ajax ?
are you calling a WCF service from inside an ajax page?
why does the server need the clients session?
in general i would make the service not need that session state on the server.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.