会话超时时提醒用户 [英] alert user when session time out

查看:174
本文介绍了会话超时时提醒用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个问题,就是当我们在页面上进行工作时,会话时间会提醒用户,而我们希望页面处于空闲状态时意味着页面上没有工作,那么会话时间应该警告用户.这样做吗??

感谢您的帮助...



i have a problem that is when we are doing work on a page then session time alert the user,while we want when the page is in idle condition means there is no working on page,then session time should be warn the user.How to do this????

Thanks for help...

推荐答案

尝试AJAX

try AJAX

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ajaxtimer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hid_Ticker.Value = new TimeSpan(0, 0, 0).ToString();
        }
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        hid_Ticker.Value = TimeSpan.Parse(hid_Ticker.Value).Add(new TimeSpan(0, 0, 1)).ToString();
        lit_Timer.Text = "Time spent on this page: " + hid_Ticker.Value.ToString();
        if (hid_Ticker.Value == "00:00:15")
        {
            Response.Redirect("http://"+fld_Name.Text);
        }
    }

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        lit_Name.Text = "Thanks. You are redirected to: " + fld_Name.Text;
    }
}




检查此帖子
Hi,

Check this post


希望这会解决您的问题. .

创建一个warning.aspx页面,并在其中放置ur警告消息和确定"按钮..
并创建一个全局js文件,并将以下代码放入其中.
Hope this will sort ur problem...

cretae a warning.aspx page and put ur warning message and Ok button there..
and create a global js file and place the below code inside it.
   function Timeout()
   {
       //have hardcoded the session timeout below..u can get it from code behind
       window.setTimeout(DisplayWarning,90000-12000)//this will display warning after 13 min from page load
   }
   function DisplayWarning()
   {
      //display ur warning here
       var  newwindow =window.open( "warning.aspx", "WarningTitle",  "channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=330,height=220", true);
       newwindow.focus();
Timeout();
   }


在每个页面上导入此js ..并在onload上调用Timeout()函数,如..< body onload ="Timeout();"> ...在这里,您可以想到更好的解决方案,例如从一个实例调用timeout函数常见的地方..例如,有一些父类

在warning.aspx页面中,添加以下代码


Import this js on every page..and call Timeout() function on onload like ..<body onload="Timeout();">...here u can think of a better solution like calling the timeout function from one common place ..ex.having some parent class

In warning.aspx page add below code

function CloseWindow()
{
   var bclicked = "<%=bclicked%>";
    if(bclicked ==  "True" || bclicked ==  "true" )
    {
        window.close();
    }
}


在onload上调用此CloseWindow()函数,如<body onload="CloseWindow();">

并且在代码背后的代码中应该是..


Call this CloseWindow() function on onload like <body onload="CloseWindow();">

and In code behind the code shud be..

public bool bclicked = false;
protected void Page_Load(object sender, EventArgs e)
{
    bclicked = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
    bclicked = true;
}


这篇关于会话超时时提醒用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆