现在的位置: 首页 > 综合 > 正文

关闭IE之前执行数据库操作

2014年02月03日 ⁄ 综合 ⁄ 共 1583字 ⁄ 字号 评论关闭

 经测试成功,其原理就是利用Anthem控件的无刷调用服务端事件。

前台页

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ToBoyUrl.aspx.cs" Inherits="ToBoyUrl"  EnableViewState="False"%>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>关闭IE之前进行数据库操作</title>
  6.     <script  language="javascript" type="text/javascript">   
  7.   window.onbeforeunload   =   function()   
  8.   {   
  9.         if(document.body.clientWidth-event.clientX< 170&&event.clientY< 0||event.altKey) 
  10.         {   
  11.             Anthem_InvokePageMethod("LogOff",['system'],aa);
  12.         }
  13.   }
  14.   
  15.  function aa(result)
  16.  {
  17.  }
  18.   </script>
  19. </head>
  20. <body>
  21.     <form id="form1" runat="server">
  22.     <div>
  23.          </div>
  24.     </form>
  25. </body>
  26. </html>

后台代码

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.HtmlControls;
  10. using DataAccess;
  11. public partial class ToBoyUrl: Page
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.         Anthem.Manager.Register(this);
  16.     }
  17.     [Anthem.Method]
  18.     public string LogOff(string strID)
  19.     {
  20.         try
  21.         {
  22.             string strSql = string.Format("Update z_user set lastlogoutdate=sysdate where UNUM='system'");
  23.             DbHelp db = new DbHelp();
  24.             db.ExecuteNonQuery(strSql);
  25.             db.Dispose();
  26.             return strSql;
  27.         }
  28.         catch
  29.         {
  30.             return "失败了!";
  31.         }
  32.     }
  33. }

不过偶尔出现IE内存泄漏的情况. 希望有高手更好的解决方案

 

 

 

 

【上篇】
【下篇】

抱歉!评论已关闭.