Session variables won't persist - Index was outside the bounds of the array

Posted on 2004-11-01
Medium Priority
Last Modified: 2008-02-01
I've asked this before but it's really critical I solve this problem.  I have traced the error to the fact that the session variables loose their values after the browser has been idle for a couple of minutes.
I've tried playing with the web.config and adjusting the time there, but not luck.  I've tried several other things like putting this in the HTML display:
<body bgColor="#ffffff" MS_POSITIONING="GridLayout" onLoad="window.setTimeout(&quot;location.href='TimeoutMessage.aspx'&quot;,99999999)">
but I don't know if the 9's are miliseconds or seconds or minutes or if I've over done it and it reset to the default or what.
I've dont this as well:
            <script language="javascript">
            function renew()

No luck.  Here is the error message.

Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
   BlountOrder.plist.setUpEnvironment() +1786
   BlountOrder.plist.Page_Load(Object sender, EventArgs e) +10
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
Question by:dcass
  • 7
  • 5

Expert Comment

by:Rodney Helsens
ID: 12464224
How have you concluded that session values are your problem? what is the code that is executing in this BlountOrder.plist.setUpEnvironment() method line +1786?

I'm sure you are already aware of the setting in web.config, which sets timeout to 20 minutes

   <sessionState mode="InProc" stateConnectionString="tcpip=" sqlConnectionString="data source=;Trusted_Connection=yes" cookieless="false" timeout="20" />

Author Comment

ID: 12464294
I'm sure about that the session variables have lost their value.  The web.config time-out is 20 minutes - I haven't timed it, it's not lasting 20 minutes.  I need to extend indefinitely.  Is there a limit? I have it set to 60,  and it's not working.
            sqlConnectionString="data source=;user id=sa;password="

Expert Comment

ID: 12464343
those are milliseconds in the setTimeout method. I can sense that your aspnet_wp process is getting recycled every now and then, thats the foremost reason for losing session prior to its timeout setting. aspnet_wp can recycle due to so many reasons, like modifying global.asax file, or modifying any file or content in the bin folder, or session timeout. Also make sure you are not changing session timeout settings anywhere, also try to access other session variables along with the one causing error, see if the entire session is gone or just that variable
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 12464407
It's the entire session.  
Can any of the code I'm using in the original question above cause this?

Expert Comment

ID: 12464446
it could be so many reasons. I would suggest you build another test web app, and see if its happening the same with that application also. It should take only couple of minutes to build a test app

Author Comment

ID: 12464484
Yes, they all behave the same way on every server - mine, their test server and the live server.
I can't believe that everyone doesn't have this problem that uses session variables. and that there is not a simple solution.
I have the test server set to 60 and the live server set to 1000.  That's why I was asking if there was a limit and it's getting reset.

Expert Comment

ID: 12464631
I am not really sure about the session timeout limit, but you should never keep the session timeout more than a reasonable amount. Remember we save so much stuff in session for each user, if we keep that session idling in the server memory, soon your server will runout of memory and more problems for you. THe best bet would be to look at the system event log to see the reason why aspnet_wp is recycling. So, please look at the event log and post the message here.

Again the following is from the msdn documentation why aspnet could be recycled

When using the in-process session-state mode, session-state data is lost if
aspnet_wp.exe or the application domain restarts. These restarts commonly
occur in the following circumstances:

##Setting an attribute in the <processModel> element of the application's
Web.config file that causes a new process to start when a condition is met,
such as memoryLimit.

##The Global.asax or Web.config file is modified.

##Changes to the \Bin directory of the Web application.

##Antivirus software scans and modifies the Global.asax file, the
Web.config file, or a file in the \Bin directory of the Web application.    

Expert Comment

ID: 12464723
Take a look at this following link, it talks about a bug about aspnet_wp getting recycled due to deadlock


Author Comment

ID: 12469815
Unfortunately, this patch is for 1.0.  We are developing in and running 1.1.
None of the other scenarios are possible.  It happens on the three systems plus my laptop that I work on (so 4 total).  Same code, same behavior.
We are all running different antivirus software and it shouldn't be changing any files, anyway.  We use trendmicro and panda - I'm sure they don't change code.
There is nothing in the event log about anything recycling or about aspnet at all.  How else would I be able to tell?
It is not machine specific - it must happen to everyone.  
The server has a lot of other .NET applications running.  Maybe it's picking up the wrong webconfig or something.  However, I sure it's loosing the values before the 20 minutes is up.  Is 1000 minutes over the limit?

Expert Comment

ID: 12472090
when its timing out in less than 20 minutes, I dont see any point in increasing the timeout to 1000 minutes, and yeah it is considered to be too much, may be not over the limit. As I described before, if its not the aspnet recycling, you are resetting the timout period somewhere. You can try this. When session expires, it would call Session_End event in the Global.asax.cs. So try to do something in the event handler. Remember you can write anything from that event to the browser. Response object is not available to that event. I usually try this way, whenever there is a problem with session

Create an application variable, in application_start, then in the Session_Start event handler, try to append something to it (usually the current time), then in the session_End, remove that session variable. open some page which has session variables in two browser windows, leave one window idle, and keep the other window active, and keep experimenting with the timeout settings, and see at what timeout setting it is blowing up. This approach might look too confusing, but it is just to give you some idea, how the session works. Try experimenting with this and see, if its anything useful

Author Comment

ID: 12474733
That is the most practical advice I've had and I'll do this over the next couple of days.
However, what is the heirarchy of web.config's and how does the framework decide which one to use?
Will it always use the one compiled into the project or I thought I read somewhere that it could use a different one but can't remember the circumstances.

Accepted Solution

ryerras earned 2000 total points
ID: 12474790
Your Machine.Config is the first config file every .NET application on your machine. Then your root's Web.Config will over ride the settings in the machine.config, then your sub directories config file will over ride your roots config file

Expert Comment

ID: 12699368
There is only one participant in this question other than the original asker;). So I am also waiting for the askers decision

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question