-2

I have a asp.net / C# site with multiple pages in an specific order. If there is no user interaction (mouse movement or keypresss) on the page for 1 min, the user should be redirected to the next page (I allready know the url from the next page).

What's the best way to accomplish that? Thnx in advance.

EDIT:

So far I have some code that was written by someone else in C# / VB:

    Response.AppendHeader("Refresh", string.Format("{0}; url={1}", DisplayDuration.ToString(), NextPage));

The display duration is defined in a DB.

Christian
  • 85
  • 1
  • 8

2 Answers2

-1

From the Question I am guessing that If a User is Idle for 1 Min he will be redirected to some page you can use JavaScript for this purpose like

var seconds = 50
var minutes = 0
function display() {
   if (seconds <= 0) {
       minutes -= 1
       seconds = 59
    }
    if (minutes < 0) {
       window.location = '<%=Page.ResolveUrl("~/PageName.aspx?")%>';
        }
    else {
       seconds -= 1
       if (seconds <= 10 && seconds>8) {
           var conf = confirm("Your Session is going to expire!");
           if (conf == true) {
               window.location = window.location.pathname;
           }
           else {
                window.location = '<%=Page.ResolveUrl("~/PageName.aspx")%>';
            }
        }
document.getElementById('<%=lblsessiontime.ClientID%>').innerHTML = "Session expires in : " + minutes + "." + ("0" + seconds).slice(-2)
setTimeout("display()", 1000)
 }

}

Using the above Javascript a label in the Page will be used to display Session Time ticking in seconds(1 Min) like shown in the below Picture(in Picture the Session timing is 8 Minutes) if it reaches 0 then the User will be redirected to the page we have specified in the Code.

Session Timing

Rajesh
  • 1,600
  • 5
  • 33
  • 59
  • @Downvoter If you down vote my posting kindly mention the reason why you have down voted it I will try to rectify it from Next time. – Rajesh Nov 13 '14 at 09:09
-1

You can find the answer here

Rephrasing it for your scenario.

function CheckIfIdle() 
{
    var t;

  // Events to reset the timer
    window.onload = resetTimer;     
    window.onmousemove = resetTimer;
    window.onmousedown = resetTimer; 
    window.onclick = resetTimer;    
    window.onscroll = resetTimer;  
    window.onkeypress = resetTimer;

    function LoadNextPage() {
      //Here is where you have to provide the url or write your action when the user is idle
       window.location.href = 'Your next page url';
    }

    function resetTimer() {
      clearTimeout(t);
     // time is in milliseconds, please change the time accordingly
      t = setTimeout(LoadNextPage, 10000);  
    }
 }

Call the method CheckIfIdle in body onLoad to start listening.

Credits : Here

Community
  • 1
  • 1
Rama Kathare
  • 920
  • 9
  • 29