locked
Keeping track o SQL Server session state SessionId RRS feed

  • Question

  • User-1121540557 posted

    Hi all,

    When i try to store the current session id in a public string, al is fine, but when the session expires on the page i can`t use this session id anymore for checking if the current session is valid..

    I`m using SQL Server session state...and it works fine...but i don`t have a clue how to check the current session with the last session.

    Here is my code:

       public string sCurrentSession; 
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
            string sCheckSession = Context.Session.SessionID.ToString();
    
            string sCurrenSessionID = Session.SessionID.ToString();
            if (!IsPostBack)
            {
    
            }
            else
            {
                if (sCurrentSession != sCheckSession)
                {
                    Response.Redirect(@"Logout.aspx");
                }
            }
            if (Request.IsAuthenticated)
            {
               sCurrentSession  = Session.SessionID.ToString();
            }
         }

     

    Hope anybody knows the anwser...

    Best regards,

    Mark

    Monday, June 25, 2012 1:50 PM

Answers

  • User1954304945 posted

    Hi,

    when the session expires on the page i can`t use this session id anymore for checking if the current session is valid
    A session is considered active as long as requests continue to be made with the same SessionID value. If the time between requests for a particular session exceeds the specified time-out value in minutes, the session is considered expired. Requests made with an expired SessionID value result in a new session. Usually, if the Users’ session is out, they need to login again. So, please set a proper Session timeout value, if the users’ session is out, just ask them to login, and then generate a new Session to store their login information. For more detail information, please refer to the following document.

    http://msdn.microsoft.com/en-us/library/ms178581.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2012 1:55 AM