每分钟加载下一页 - asp.net c#

时间:2014-11-13 08:43:31

标签: c# asp.net redirect

我有一个asp.net / C#网站,其中包含特定订单的多个页面。如果页面上没有用户交互(鼠标移动或按键)1分钟,则应将用户重定向到下一页(我已经知道下一页的URL)。

实现这一目标的最佳方法是什么? Thnx提前。

修改

到目前为止,我有一些代码是由C#/ VB中的其他人编写的:

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

显示持续时间在DB中定义。

2 个答案:

答案 0 :(得分:-1)

从问题我猜测如果用户空闲 1分钟,他将被重定向到某个页面,您可以使用JavaScript来实现此目的,例如

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)
 }

}

使用上面的Javascript页面中的标签将用于显示 会话时间以秒为单位(1分钟),如下图所示(如果会话时间为8分钟),如果达到0,则用户将被重定向到我们在代码中指定的页面。

Session Timing

答案 1 :(得分:-1)

您可以找到答案here

根据您的情况重新说明。

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);  
    }
 }

调用正文CheckIfIdle中的方法onLoad开始收听。

致谢:Here