






















There is no event in the Global.asax to deal with browser closing. When we need to call Session_End() upon user close the browser. We can use a indirect way to call Session_End() to do some clearance jobs. Actually, we do not need to call Session_End() to do some clearance jobs upon closing browser in client.
Here's the steps:
1). to catch browser cloing event in .aspx page, simply, just add onbeforeunload event to the <body > tag.
<body onbeforeunload= 'CloseWindow();' >
</body>
2. In the head of .aspx page, add the following code to load another page to do clearance jobs. In the following codes, it would transfer to clearance.aspx page, and in the Page_Load() of clearance.aspx, we could do clearance job, or fire the Session_End() event by abandon Session.
<script language ="javascript">function CloseWindow()
{
window.location = '../clearance.aspx';
alert('You are about to close the window');
}
</script>
3.in the Page_Load() of Clearance.aspx, add the following code to fireup Session_End() or do clearance(Attention, make sure your web application is in the In-Proc Session mode, web.config use In-Proc Session mode by default).
HttpContext.Current.Session.Abandon();
// to do clearance bellow:
// ...
Reference:
http://gridviewguy.com/ArticleDetails.aspx?articleID=108
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。