Detecting and Handling Session TimeOut

Last post 01-28-2009 10:26 AM by budugu. 6 replies.

Sort Posts:

  • Detecting and Handling Session TimeOut

    01-28-2009, 9:44 AM
    • Member
      169 point Member
    • RDowdall
    • Member since 06-02-2005, 12:56 PM
    • Atlanta
    • Posts 91

    I have an application that uses Session and will throw an exception if the Session has timed out. What is the best way to handle session time-outs?

     

    Thank-you,

     

    RD

    RD

    The creator of the universe works in mysterious ways. But he uses a base ten counting system and likes round numbers.
    - Scott Adams
  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:01 AM
    Answer
    • All-Star
      59,859 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,544
    • TrustedFriends-MVPs

    RDowdall:

    I have an application that uses Session and will throw an exception if the Session has timed out. What is the best way to handle session time-outs?

     

    Thank-you,

     

    RD

    After login you can add the username to a Session variable

    Session("user") = "UserName"

    On the page load Check

    if Session("UserName") is Nothing Then

    Response.Redirect("Login.aspx")

    End if

    Thus whenever session expires user will be sent back to login page

     

  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:02 AM
    • Member
      612 point Member
    • F.B. ten Kate
    • Member since 05-28-2008, 7:50 AM
    • Rotterdam, The Netherlands
    • Posts 147

     I've done this in the past in global.asax (Session_End), but there might be other ways, why exactly do you want to throw an exception when ever a session times out? in what context are you trying to do this?

    Greetings,

    F.B. ten Kate

    ps. Don't forget to mark helpfull replies as answer
  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:04 AM
    Answer
    • Participant
      1,064 point Participant
    • siedler
    • Member since 10-02-2008, 4:34 PM
    • Germany
    • Posts 168

    Hi,

    read this site. it show's how to redirect to another page with javacript, without user interaction

     

    http://stackoverflow.com/questions/484964/asp-net-push-redirect-on-session-timeout

    -------------------------------------------------
    Jürgen
  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:18 AM
    • Member
      169 point Member
    • RDowdall
    • Member since 06-02-2005, 12:56 PM
    • Atlanta
    • Posts 91

    Thanks, That was the simplest solution

    RD

    The creator of the universe works in mysterious ways. But he uses a base ten counting system and likes round numbers.
    - Scott Adams
  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:23 AM
    • All-Star
      59,859 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,544
    • TrustedFriends-MVPs

    RDowdall:
    Thanks, That was the simplest solution

     

    If your query is resolved mark the post that helped you as answer

  • Re: Detecting and Handling Session TimeOut

    01-28-2009, 10:26 AM
    Answer
    • All-Star
      25,024 point All-Star
    • budugu
    • Member since 01-12-2006, 2:15 PM
    • North Carolina
    • Posts 3,741

    RDowdall:
    What is the best way to handle session time-outs?

    At page level you can check session on each pageload like this.. 

    if(Session["Session_Name"]==null) 
    
    Response.Redirect("login.aspx"); 
    

     Or

     If you want to redirect the page immediately(with out any user action) after session expires then consider this approach. HTTP is stateless, so you have to refresh the page after session expired. Check this code..  

    Response.AppendHeader("Refresh",
    Convert.ToString((Session.Timeout * 60) + 15) & ";
    URL=Login.aspx")
    

     

    Check this link..

    http://forums.asp.net/p/1373998/2882266.aspx#2882266

    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
Page 1 of 1 (7 items)