Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Session variables time out

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
dcass
Asked:
dcass
  • 3
  • 2
  • 2
  • +2
1 Solution
 
shekhar_kCommented:
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
 
dcassAuthor Commented:
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
 
mmarinovCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
mmarinovCommented:
0
 
dcassAuthor Commented:
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
 
shekhar_kCommented:
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
 
philippe_leybaertCommented:
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
 
dcassAuthor Commented:
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
 
CetusMODCommented:
PAQed, with points refunded (500)

CetusMOD
Community Support Moderator
0
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now