locked
Session Timeout and Global.asax RRS feed

  • Question

  • User769474054 posted

    I have the following requirement and here are my implementation details for this.

    Statement:- There is a request page (abc.aspx) where user enter info. I will set a lock flag in DB when user edit something on Page and reset/Unlock the flag when his session timesout or closes the browser.

    Soln:-

    since editing is much of client side, I am using a Jquery Ajax call to server method(Static) and using another static method to set the flag in DB. 

    If a user opens multiple tabs, its considered as same session and thus I am storing this list in Session variable in my Static method and when Session times out I can use this list and unlock the requests in DB.

    I am setting like this in my abc.aspx

    BLRequest.UpdateRequestLockStatus(requestId, currentUser.UID);
                        listOfLockedReq = HttpContext.Current.Session["CurrentLockedReqIds"] != null ? (List<int>)HttpContext.Current.Session["CurrentLockedReqIds"] : new List<int>();
                        listOfLockedReq.Add(Convert.ToInt32(reqID));
                        HttpContext.Current.Session["CurrentLockedReqIds"]=listOfLockedReq;

    I am trying to access  this in Session_End of Global.asax but its returning null or a different Session ID. Here is my snippet in Session End method of Global.asax

    List<int> ListoflockedreqPerUser = (List<int>)(Session["CurrentLockedReqIds"]);
                        if (ListoflockedreqPerUser != null && ListoflockedreqPerUser.Count > 0)
                        foreach (var req in ListoflockedreqPerUser)
                            BLRequest.UpdateRequestLockStatus(req, 0);

    For some reason, I couldn't access the requestIds set in the session variable, anyone know why? or what am I doing wrong?

    or Is there a better way of doing this? pls comment.

    Thursday, July 16, 2015 8:45 PM

Answers

  • User-271186128 posted

    Hi pavanlalit,<!--?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" /--><o:p></o:p>

    According to your code and description, I create a sample using your code, it worked well on my side. I can get the session value in Session_End event. I suggest you check the session state Mode property. <o:p></o:p>

    With reference this article, I found that:<o:p></o:p>

    The Session_OnEnd event is supported only when the session state Mode property is set to InProc, which is the default. If the session state Mode is StateServer or SQLServer, then the Session_OnEnd event in the Global.asax file is ignored. If the session state Mode is set to Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider.<o:p></o:p>

    So, you could try to use Inproc mode.

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2015 5:24 AM