Loading ...

Session variable question

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Session variable question

Session variable question

Posts under the topic: Session variable question

Posted: 8/20/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51

I am using a session variable on a couple different pages within my application.  If my site sits idle for a period of time I get a runtime error when I click on anything.  From what I have read I think it is because I need to do a "proper" null check.  Is this done in the global.aspax within the Session_start? or just on the pages where I am using the Session variable?

 

thanks in advance


Posted: 8/22/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74

Hi Mike,

You should check if this value is null at the page where you use it. 

Best Regards,

Gjorgji


Posted: 8/22/2011

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

Posted: 8/24/2011

Lurker 55  points  Lurker
  • Joined on: 7/14/2011
  • Posts: 7
  Answered

If you want to increase the time before the session is lost then change the timeout property for the SessionState node in the web.config.

I had a client who hated the timeout, so we lengthened the timeout to an hour.

Another method would be to implement a timer in your project that performs a postback periodically (e.g, every 19 minutes if the timeout is 20 minutes). This way the session would not be lost.

However, if these examples are not relevant to your situation then you should catch the timeout error and take the user to an error page that lets them know their session timed out.


Posted: 9/29/2011

Lurker 60  points  Lurker
  • Joined on: 9/28/2011
  • Posts: 8

You can set the Condition for the  Session Expire ...If the Session is Null then Redirect the Page to the Index Page..Then if your Session may be Expire then Your page automatically redirect to the index page...


Posted: 12/1/2011

Lurker 5  points  Lurker
  • Joined on: 12/1/2011
  • Posts: 1

In each page page load event check the session is null if the session is null then redirect the page to login page.

 

protected void Page_Load(object sender, EventArgs e)
{

        if (Session["Session_Name"] == null)
       {
               Response.Redirect("Login.aspx");
        }

        //

}


Page 1 of 1 (6 items)