关闭ie窗口清空Session的解决方法
发布时间:2023-09-15 14:56:16 所属栏目:教程 来源:
导读:代码如下:
//function window.onunload() { alert('这就是你要做的事,关闭网页之后做的! '); location = 'SessionClear.aspx'; }
//function window.onbeforeunload() { alert(
//function window.onunload() { alert('这就是你要做的事,关闭网页之后做的! '); location = 'SessionClear.aspx'; }
//function window.onbeforeunload() { alert(
代码如下: //function window.onunload() { alert('这就是你要做的事,关闭网页之后做的! '); location = 'SessionClear.aspx'; } //function window.onbeforeunload() { alert('这就是你要做的事,关闭网页之前做的! ') } function window.onunload() { if ((window.screenLeft >= 10000 && window.screenTop >= 10000) || event.altKey) { alert(window.screenLeft+","+window.screenTop); //用户非正常关闭时需要触发的动作 location = 'Handler1.ashx'; } } </script> Handler1.ashx: 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.SessionState; namespace WebApplication1 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Handler1 : IHttpHandler,IRequiresSessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Session.Abandon(); context.Session.Clear(); } public bool IsReusable { get { return false; } } } } 解释: 一般的会员形式的网站,在会员登陆后都会建立会话或者Cookie,然后需要在会员退出时点退出连接或按纽退出。在会员直接关闭窗体的时候,没有触发涉及到退出的一系列退出。而这些要等到服务器会话过期才会被清除掉。 (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐