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

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rodney HelsensCommented:
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" />
dcassAuthor Commented:
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="
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

dcassAuthor Commented:
It's the entire session.  
Can any of the code I'm using in the original question above cause this?
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
dcassAuthor Commented:
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.
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.    
Take a look at this following link, it talks about a bug about aspnet_wp getting recycled due to deadlock;EN-US;321792
dcassAuthor Commented:
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?
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
dcassAuthor Commented:
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.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
There is only one participant in this question other than the original asker;). So I am also waiting for the askers decision
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

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.