Solved

Session variables time out

Posted on 2004-05-03
10
285 Views
Last Modified: 2011-10-03
Session variables time out and become unavailable.

I have increased the web.config timeout:
 <sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;user id=sa;password="
            cookieless="false"
            timeout="99999"
I have increased the IIS site timeout:
IIS site Properties/Configuration/Options/Enable Session State = 40 minutes and ASP script timeout = 9999.

It only takes a couple of minutes to get the time out error:
Server Error in '/BlountOrder' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 90:                         Session["tablename2"]=Request["Dtl"];
Line 91:            
Line 92:                   if (Session["Menu"].ToString() == "")
Line 93:                         Session["Menu"] = "Tables";
Line 94:                   //else      
 

Source File: c:\inetpub\wwwroot\blountorder\list.aspx.cs    Line: 92

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   BlountOrder.list.renderTableCustom() in c:\inetpub\wwwroot\blountorder\list.aspx.cs:92
   BlountOrder.list.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\blountorder\list.aspx.cs:50
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


Please HELP!!!
Thanks in advance -

 
0
Comment
Question by:dcass
  • 3
  • 2
  • 2
  • +2
10 Comments
 

Expert Comment

by:shekhar_k
ID: 10977299
I think it is not the problem with Session expiry. when the page is loaded for the first time the key "Menu" is not created in the session. So when you put a check like :

 if (Session["Menu"].ToString() == "")
                  Session["Menu"] = "Tables";

it tries to get the value from the Session and doesn't find it. Check if "Menu" is created in the session before you try to access it. Try putting this code in a try catch block and see if an exception is raised.

try
{
 if (Session["Menu"].ToString() == "")
                  Session["Menu"] = "Tables";
}
catch(Exception ex)
{
Response.Write(ex.Message);
}

If it doesn't work load the Page_Load() function so that we can see if there is anything wrong there. your configuration for the session look fine.

hope it helps....
0
 

Author Comment

by:dcass
ID: 10978154
That's not it - I've already run that program several times before I get the error.
I have added a redirect to a time out aspx on the body onload function and that is working, but how do I increase the timeout to 8 hours and what are the ramifications of doing that?
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10978216
if the problem is with the not created "menu" key in the Session collection i'll suggest you to use

if ( Session["Menu"] !=  null )
 {
  if ( Session["Menu"].ToString() == "" )
     Session["Menu"] = "Tables";
 }
else
 {
   Session["Menu"] = "Tables";
 }
hth
b..m
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10978347
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dcass
ID: 10996150
mmarinov - That is not going to work - I can't default any of the session variables (especially this one) and even get close to what they should be.  And  like I said, if it was that the session variable had not been created then it wouldn't have worked the tens of times it does before it times out - so we know for sure that it doesn't need a programming fix.
Plus, if I remove that session variable reference, the error goes on to the next session variable.

Maybe you haven't seen this before, but I read somewhere that you can measure how much time is left and send a notification pop-up like Bank of America and allow them to reset the timer.   I'm looking for that code or where to find that code.

Your link only tells me it's in the web.config file but I have reset it for this site and it still times out in a couple of minutes.
There must be a limit that if you go over, it resets it back to about two minutes.  Is the web.config setting in seconds or minutes?

Thanks
0
 

Expert Comment

by:shekhar_k
ID: 11002050
Web.config timout setting is in minutes. So for your case value of 240 should do. Moreover to my knowledge if session expires you dont get NullReferenceException, in that case it should get "page cannot be displayed" on the browser.

It might be possible that giving a very large value like 99999 may reset the timeout to 20minutes(default). try changing the timeout value to a more reasonable number.

-Shekhar
0
 
LVL 4

Expert Comment

by:philippe_leybaert
ID: 11022777
Overwriting DLL files in your bin directory will also cause a session to expire immediately (for example, after publishing an updated version of the website)
0
 

Author Comment

by:dcass
ID: 11179444
Please close.
I am posting the answer(s) to this so that maybe the next person doesn't have to struggle with this.
To stop the CLIENT side tineout, add this:
<body  onLoad="javascript:window.setTimeout('renew()',15*60*1000);">
To stop the SERVER side timeout, add this:
set web.config to have a session timeout of 20 minutes
then add this and as long as they have their session open, it will keep renewing:
<script language="javascript">
function renew()
{
 alert(location.href);
 location.href = location.href;
 location.reload(true);
}
</script>


0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11271371
PAQed, with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

20 Experts available now in Live!

Get 1:1 Help Now