如何在会话超时时调用事件处理程序 [英] How do I invoke an event handler on session timeout

查看:111
本文介绍了如何在会话超时时调用事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个很酷的会话时间代码弹出警报.
如何在会话超时时调用事件处理程序
我需要在页面上输入数据以节省会话超时时间.

我在看Page方法和示例,建议吗?



I found this cool session time code popup alert.
how do I invoke an event handler on session timeout
I need the data enter on a page to save minute before session time out.

I am looking at Page Method and examples, suggestions?



private void CheckSessionTimeout()
{
string msgSession = "Warning: Within next 3 minutes, if you do not do anything, our system will redirect to the login page. Please save changed data.";
//time to remind, 3 minutes before session end
int int_MilliSecondsTimeReminder = (this.Session.Timeout * 60000) - 3 * 60000;
//time to redirect, 5 miliseconds before session end
int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 5;

string str_Script = @"
var myTimeReminder, myTimeOut;
clearTimeout(myTimeReminder);
clearTimeout(myTimeOut); " +
"var sessionTimeReminder = " + int_MilliSecondsTimeReminder.ToString() + "; " +
"var sessionTimeout = " + int_MilliSecondsTimeOut.ToString() + ";" +
"function doReminder(){ alert(''" + msgSession + "''); }" +
"function doRedirect(){ window.location.href=''login.aspx''; }" + @"
myTimeReminder=setTimeout(''doReminder()'', sessionTimeReminder);
myTimeOut=setTimeout(''doRedirect()'', sessionTimeout); ";

ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(),
"CheckSessionOut", str_Script, true);
}

推荐答案

尝试查看 Session_End Global.asax文件的> [^ ]事件.

干杯
Uwe
Try looking at the Session_End[^] event of the Global.asax file.

Cheers
Uwe


您无法在Page事件中执行任何操作,因为在页面事件结束后在服务器上进行处理(基本ASP.NET生命周期).

setTimeout函数的第一个参数是发生超时时要调用的函数,在这种情况下为doReminder和doRedirect.在您的情况下,您需要提供强制执行提交的功能,或调用用于保存数据的任何方法.

找到很酷"的代码很好,但是您必须能够理解它并确定它是否符合您的需求.
There is nothing you can do in a Page event because after the page has been processed on the server it is disposed (basic ASP.NET lifecycle).

The first parameter of the setTimeout function is the function to call when the timeout happens, in this case, doReminder and doRedirect. In your case you would need to provide function that will force a submit, or invoke whatever method you use to save the data.

Finding "cool" code is fine but you must be able to understand it and determine if it fits your needs.


这篇关于如何在会话超时时调用事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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