Hi
We're getting a problem where session variables are lost between page requests. I set a session variable (affilaite id) when a session starts in session_start event in global.asax. With tracing enabled i can see that this variable is resident on the initial page request. When i navigate to a new page however, all session variables are lost.
This has only just started happening fairly recently and I cannot find any particular piece of code that may be causing it. I've read stuff on the web about worker process recycling but if this is happening every time the user requests a page then somethings seriously wrong.
This is happening on 2 XP development machines and a Win2K3 server machine.
Any ideas
Ben
![]() |
0 |
![]() |
Can you provide a few more details, please.
Firstly, what session state store are you using? My guess would be inproc, but can you confirm that by checking in web.config.
Secondly, are you using cookie-based sessions? Can you confirm (via tracing) that the cookie is being sent from the client to the server?
Thirdly, have you set a breakpoint on your Session_Start event handler and then tested that it gets hit on every request. It should do if the session is being lost.
Next, have you any code that calls Session.Abandon()? Or any code in, say, a master page or base page class that might inadvertently be resetting the session variables?
Given that the problem is occurring on all the machines, the most likely cause is a configuration/coding error. It is unlikely to be a worker process recycling problem on a simple XP development machine, and it certainly shouldn't be occurring on every page request.
Finally, have you tried adding two test pages, one of which simply sets a value into a Session variable and then calls Response.Redirect to the second page which displays the variable? Proving that this works is indicative that the problem lies within your code, and will also provide an excellent (and small) testing ground to isolate the problem.
Regards
Dave
![]() |
0 |
![]() |
Hi
Thanks for the response. Here's the answers to your questions:
1) We're using InProc
2) Yes we are using cookie based sessions and the session cookie is present across al requests
3) Session_Start is hit on every request
4) We don't call Session.Abort() anywhere
5) Using the two test pages did work.
So it's safe to assume that it's the code. Any suggestions on tracking it down?
Thanks for your help
Ben
![]() |
0 |
![]() |
An interesting observation while trying to debug this:
When the inital page loads and the user navigates to another page using a hyperlink, session_start is fired once. If they navigate away using anything that causes a postback (Button, ImageButton) and whose handler calls response.redirect, session_start is called twice. Once they've navigated away once from the main page however, all subsequent navigation, whether by postback/response.redirect or using plain hyperlink, DOES NOT fire session_start.
I've tried changing the initial start page to something other than default.aspx and the problem occurs for some pages but not others. I can't see any obvious difference between them in terms of functionality. For example, default.aspx has no C# code otehr than an empty Page_Load handler.
All pages share a common base page however that override OnPreInit and OnLoad virtual methods but commenting these out doesn't fix the problem.
Putting a breakpoint on session_start, the opening the initial page (default.aspx) on a new debugging session shows the following call stack:
ConciergeDesk.Site.Shop.DLL!ConciergeDesk.Site.Shop.Global.Session_Start(object sender = {System.Web.SessionState.SessionStateModule}, System.EventArgs e = {System.EventArgs}) Line 27 C#
System.Web.dll!System.Web.SessionState.SessionStateModule.RaiseOnStart(System.EventArgs e) + 0x8c bytes
System.Web.dll!System.Web.SessionState.SessionStateModule.CompleteAcquireState() + 0x9b bytes
System.Web.dll!System.Web.SessionState.SessionStateModule.BeginAcquireState(object source, System.EventArgs e, System.AsyncCallback cb, object extraData) + 0x21f bytes
System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x5b bytes
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.AsyncEventExecutionStep}, ref bool completedSynchronously = true) + 0x9c bytes
System.Web.dll!System.Web.HttpApplication.ResumeSteps(System.Exception error) + 0x163 bytes
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x91 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {System.Web.Hosting.ISAPIWorkerRequestOutOfProc}) + 0x194 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x62 bytes
System.Web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(System.IntPtr ecb, int iWRType) + 0x57 bytes
[Appdomain Transition]
[Native to Managed Transition]When navigating away from that page, session_start is fired and with the following call stack:
ConciergeDesk.Site.Shop.DLL!ConciergeDesk.Site.Shop.Global.Session_Start(object sender = {System.Web.SessionState.SessionStateModule}, System.EventArgs e = {System.EventArgs}) Line 27 C#
System.Web.dll!System.Web.SessionState.SessionStateModule.RaiseOnStart(System.EventArgs e) + 0x8c bytes
System.Web.dll!System.Web.SessionState.SessionStateModule.CompleteAcquireState() + 0x9b bytes
System.Web.dll!System.Web.SessionState.SessionStateModule.BeginAcquireState(object source, System.EventArgs e, System.AsyncCallback cb, object extraData) + 0x21f bytes
System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x5b bytes
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.AsyncEventExecutionStep}, ref bool completedSynchronously = true) + 0x9c bytes
System.Web.dll!System.Web.HttpApplication.ResumeSteps(System.Exception error) + 0x163 bytes
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x91 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {System.Web.Hosting.ISAPIWorkerRequestOutOfProc}) + 0x194 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x62 bytes
System.Web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(System.IntPtr ecb, int iWRType) + 0x57 bytes
[Appdomain Transition]
[Native to Managed Transition]What does the [Appdomain Transition] mean? Is this normal for a standard navigation?
![]() |
0 |
![]() |
For anyone who's interested the cause was due to setting EnableSessionState to false. The pages that were triggering session_start when navigating away from them all had this set in the @page declaration.
I was under the impression that session state was still preserved with this setting, just that you couldn't modify it, only read it.
Ben
![]() |
0 |
![]() |