locked
Move the user to default page if no activity on Sub Page RRS feed

  • Question

  • User-617859429 posted

    Hi

    I am looking to move the user to Main page if no activity on Sub page. I will also be performing some DB activity once reverted to main page

    Also let say if the user closes the IE then how to perform that DB Activity (Perform some action) 

    ----------

    2) Also is there a way to display a message for time out. can't use JQuery. only Java Script.

    and again if time out expires go to main page and perform some DB action at backend.

    and again if they close IE..

    THank You

    Monday, March 5, 2018 2:13 PM

All replies

  • User475983607 posted

    muhammadazeemazam

    I am looking to move the user to Main page if no activity on Sub page. I will also be performing some DB activity once reverted to main page

    There's missing context.  What is a main page and a subpage?  What does no activity mean?  How will the main page be notified of no activity?

    muhammadazeemazam

    Also let say if the user closes the IE then how to perform that DB Activity (Perform some action) 

    Modern browser block this behavior in favor of the user's experience.

    muhammadazeemazam

    2) Also is there a way to display a message for time out. can't use JQuery. only Java Script.

    JavaScript has built-in timers.

    https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Code_snippets/Timers

    muhammadazeemazam

    and again if time out expires go to main page and perform some DB action at backend.

    Use AJAX.  You can Google tons of information on AJAX and example code.

    http://api.jquery.com/jquery.ajax/

    Monday, March 5, 2018 7:34 PM
  • User1400794712 posted

    Hi Khaki,

    Also let say if the user closes the IE then how to perform that DB Activity (Perform some action) 

    If you mean when user closes the IE, perform some action, we can use onbeforeunload function:

    <script>
        window.onbeforeunload = function (event) {
            var message = 'Important: Please click on \'Save\' button to leave this page.';
            if (typeof event == 'undefined') {
                event = window.event;
            }
            if (event) {
                $.ajax({
                    url: '@Url.Action("AjaxDemo","Test")'
                })
                event.returnValue = message;
            }
            return message;
        };
    </script>

    About javascript timeout function, you can use setTimeout():

    setTimeout(function(){ alert("Hello"); }, 3000); //Alert after 3 seconds

    Then like what mgebhard asked, what does Main page, Sub page and Activity mean?

    Best Regards,

    Daisy

    Tuesday, March 6, 2018 7:32 AM
  • User-617859429 posted

    Hi Guys

    1) actually I have to maintain some sates in DB

    The problem I am having is

    1) if the User closes IE OR Tab, I need to update the status in DB to release the Source which is tied to this user.

    2) if They reboot or Shut down their PC, I still need to update the status in DB to release the Source which is tied to this user.

    Thank You

    Tuesday, March 6, 2018 4:15 PM
  • User475983607 posted

    muhammadazeemazam

    1) if the User closes IE OR Tab, I need to update the status in DB to release the Source which is tied to this user.

    2) if They reboot or Shut down their PC, I still need to update the status in DB to release the Source which is tied to this user.

    This requirement is simply not possible. 

    A cache timeout handler that executes after x minutes or Session timeout might work for you. 

    SignalR or Websockets might be an option where the server can detect if the user disconnected.

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events

    Tuesday, March 6, 2018 4:36 PM
  • User753101303 posted

    Hi,

    It would be better to change your design. I never saw a convincing way to test for closing the browser and you'll never be able to know if the PC rebooted or crashed.

    Which kind of resource do you lock? If you REALLY have to you could consider that if you have no news from the user for more than the session duration he left etc...

    But once again my first move is to always try to avoid having to track user sttae in "real time". Another well know approach is to use optimistic locking.

    Tuesday, March 6, 2018 6:54 PM
  • User-617859429 posted

    hi Patric, its real time.... but now I created a job to release the source based on time stamp.

    Friday, March 16, 2018 3:59 PM