Session Timeout Issue using Application Variable RRS feed

  • Question

  • User1726813030 posted

    Hi All,

    In my web application, I want to redirect the users to their default home page whenever session timeout happens. I used the following code to make it work. In global.asax.vb I set Application("Active") = "True" in Session_End method and in Page_Load method of master page I check if Application("Active") is true, if yes then I clear this and redirect the users to home page. Below is my code:

    In Global.asax.vb

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
         Application("Active") = "True"
    End Sub

    And In Master page Page_Load

    'After session timeout redirect the users to their default pages
    Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10))
    If Application("Active") = "True" Then
         Application("Active") = "False"
    End If

    It works fine..but my question is that if all users access the website setup on a single server and if session_timeout occcurs for one user it will affect all other users also right?(in which case all the users will be redirected to their homepage when session timeout happens for one user?) How I can resolve the problem? I cannot use session variables and cannot have Response.Redirect in Session_End as there will be no response object when the session end happens.

    I am kind of confused. Can anyone please clarify this?

    Thank you very much.

    Thursday, November 8, 2012 11:48 AM


  • User1779161005 posted

    Application is a shared state bag so all users share the one state bag. You don't want to use it for this purpose.

    Session_Start is called when they are first starting, so that's sufficient for you to know they user is new.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 8, 2012 12:07 PM