Server side VB asp code on a Windows 2003 machine, asp.net 2.0* installed. We're having a weird issue where the first time a user connects to the web site, the Session_OnStart in the Global.asa fires, but the session object is null. Something simple like:
Session.Timeout = 30
causes the following error: Object required: 'Session'
The web site has been 'created' in the IIS Manager Home Directory tab, and Sessions are enabled in the Configuration page for the site.
In most cases, the session object exists if the user refreshes the page. But that first visit for a unique user always causes the error.
Suggestions? 开发者_JAVA百科The code doesn't have an error, as it worked on the old Win2000 system.
Just to reiterate: Windows 2003 Server, running IIS6, with .Net 2.0 installed. Web site is running as an application, not a virtual directory.
Figured out the problem. It was due to having more than one worker in the app pool used for the website. Since there was no guarantee which worker process would handle a client's request, and each worker process would create it's own instance of the client's session, the session would be dropped and recreated when IIS decided that a different worker process should handle a request. Problem was resolved by using only one worker process in the app pool, and getting all the other websites out of the app pool and into their own.
I'm now looking for a way to have multiple workers in the app pool but to have the client stick with the worker process. But that's a different problem that I'll research.
Quite an interesting problem.
We know that when the session is explicitly abandoned or eventually times out it is promptly destroyed. I would add code like the following, in order to guarantee it cannot happen.
If Session("test") Is Nothing Then
Response.Redirect("Whatever.asp")
End If
You could also call the code that creates your objects in this block; this way, if you detect that the session was somehow destroyed, you could recreate them.
精彩评论