用户关闭浏览器时如何调用Session_End? [英] How to call Session_End when user closes the browser?

查看:181
本文介绍了用户关闭浏览器时如何调用Session_End?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户关闭浏览器窗口时如何调用Session_End.

How to call the Session_End when user closed the browser window.

推荐答案

不可能.忘掉它.只是正确地编写您的网站,因为其他所有人都知道,没有可靠的方法可以知道用户何时关闭浏览器.您可以在登录系统中隐含超时,尽管会话结束后无论如何它们都会被注销.
Impossible. Forget about it. Just write your site properly, because everyone else knows that there''s no reliable way to know when the user closes the browser. You can impliment a timeout in your login system, although they just get logged out anyhow when their session ends.


如果没有其他选项卡或同一浏览器的其他实例正在运行,则会话将您可以通过其他方式编写代码来重置页面卸载中的会话对象

1)在global.asax中,通过Session_Start和Session_End方法初始化会话变量.
然后在页面上卸载调用Session.Abandon();和Session.Clear()方法

受保护的重写void OnUnload(EventArgs e)
{
//在此初始化Session变量或方法以清除会话
}
If no other tab or no other instance of same browser is running the session will be cleared.In other ways you can write code to reset the session objects in page unload

1) in global.asax , at Session_Start and Session_End method initialize the session variables.
then on page unload call Session.Abandon(); and Session.Clear() methods

protected override void OnUnload(EventArgs e)
{
//Here initialize the Session variables or methods to clear session
}


这篇关于用户关闭浏览器时如何调用Session_End?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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