1

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? 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.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
MonkeyWrench
  • 1,809
  • 2
  • 24
  • 48
  • sounds like you're mixing classic ASP with ASP.net Classic asp.net does not have a "configuration page" Classic ASP has nothing to do with ASP.net 2.0 If you're trying to run ASP.net you will need to rename your Global file to Global.asax. – Dee Mar 16 '11 at 19:48
  • Not trying to run any asp.net, just asp. Figured I'd list out what's installed. – MonkeyWrench Mar 17 '11 at 01:19
  • Probably the `Session` is not yet created as the Application didn't finish initializing yet (being the first request) so I guess there is no real fix for this. Do you have any other use to `Session` there, or are you just setting its `Timeout` value? – Shadow The GPT Wizard Mar 17 '11 at 10:38
  • We're initializing a bunch of user information, as well as setting the timeout value. Odd thing is that it's consistent. Every new user has it fail. It's a quick machine as well, so I'm not sure why this would a problem. It worked fine on the older, slower machine. – MonkeyWrench Mar 17 '11 at 19:01
  • create a simple test page with nothing else in it except; session("test") = 1 response.write session("test") and let us know what happens. – Dee Mar 21 '11 at 04:41
  • There aren't any problems once we get past the error in the Global.asa. We're able to add/retrieve values from the Session without a problem. It's just that initial session creation. – MonkeyWrench Mar 21 '11 at 12:18
  • @Shadow Wizard : I had the same intuition than you, but the doc clearly states that, in IIS 6, "All the built-in objects are available and can be referenced in the Session_OnStart event script." (http://msdn.microsoft.com/en-us/library/ms524776(v=vs.90).aspx). – Sébastien Nussbaumer Mar 22 '11 at 20:35
  • @MonkeyWrench : quite a lot of things changed between IIS 5 and IIS 6, and I remember that when we switched (a while ago) we faced a few issues. Could you try commenting your current Session_OnStart and create a new Session_OnStart from scratch with just the Session.Tmeout = 30 and see the result ? Maybe you're using some 3rd party component that is messing with the session ... this test would help highlight the problem. – Sébastien Nussbaumer Mar 22 '11 at 20:42

2 Answers2

2

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.

MonkeyWrench
  • 1,809
  • 2
  • 24
  • 48
0

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.