Solved

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

Posted on 2004-11-01
1,049 Views
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()
            {
            alert(location.href);
            location.href=location.href;
            location.reload(true);
            }
            </script>

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
0
Question by:dcass
    13 Comments
     
    LVL 9

    Expert Comment

    by:Rodney Helsens
    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=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20" />
     
    0
     

    Author Comment

    by:dcass
    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.
        <sessionState
                mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;user id=sa;password="
                cookieless="false"
                timeout="60"
        />
    0
     
    LVL 6

    Expert Comment

    by:ryerras
    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
    0
     

    Author Comment

    by:dcass
    It's the entire session.  
    Can any of the code I'm using in the original question above cause this?
    0
     
    LVL 6

    Expert Comment

    by:ryerras
    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
    0
     

    Author Comment

    by:dcass
    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.
    0
     
    LVL 6

    Expert Comment

    by:ryerras
    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.    
     
    -------------------------------------------------------------
    0
     
    LVL 6

    Expert Comment

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

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;321792
    0
     

    Author Comment

    by:dcass
    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?
    0
     
    LVL 6

    Expert Comment

    by:ryerras
    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
    0
     

    Author Comment

    by:dcass
    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.
     
    0
     
    LVL 6

    Accepted Solution

    by:
    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
    0
     
    LVL 6

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    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…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now