我们在键盘上跳舞,演绎最美的人生

关闭ie前使用js调用web service操作数据库

页面js
<script language="javascript">
    //关闭IE提示------------------------------------------------------------
    var i = 0
    document.onkeydown = function KeyDown() {
        if ((event.keyCode == 116) || (event.ctrlKey && event.keyCode == 82)) { //屏蔽 F5 刷新键和Ctrl + R
            i = 1;
        }
    }
    function window_onbeforeunload() {
        var a = 0;
        a = top.window.document.body.offsetWidth;
        if (event.clientY > 0 || (event.clientY < 0 && event.screenX < (a - 25))) {//屏蔽右键刷新和刷新按钮
            i = 1;
        }
        if (i != 1) {
            return "你确定要退出本系统?";
        }
    }
    function window.onunload() {  //关闭ie时清空session
        var sessionid = '<%=sessionID%>';
        if (i != 1) {
            //alert(sessionid);
            SignOutByPost(sessionid);
        }
    }
    function SignOutByPost(sessionid) {
        var data;
        data = '<?xml version="1.0" encoding="utf-8"?>';
        data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
        data = data + '<soap:Body>';
        data = data + '<SignOut xmlns="http://tempuri.org/">';
        data = data + '<SessionID>' + sessionid + '</SessionID>';
        data = data + '</SignOut>';
        data = data + '</soap:Body>';
        data = data + '</soap:Envelope>';
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        var URL = "/iOffice/prg/set/wss/ioCtlSet.asmx";
        xmlhttp.Open("POST", URL, true);
        xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlhttp.SetRequestHeader("SOAPAction", "http://tempuri.org/SignOut");
        xmlhttp.Send(data);
      
    
    }
    //-----------------------------------------------------------------
</script>

ioctlset.asmx.vb
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ioCtlSet
    Inherits System.Web.Services.WebService
    '保存折叠cookies
    <WebMethod()> _
     Public Sub SaveFoldCookies(ByVal empid As Integer, ByVal fold As Boolean, ByVal mode As String)
        Dim cookie As New ioCom.EmpCookie("ioFoldDisplay_" & mode, empid.ToString)
        cookie.ItemAdd("IsFold", fold)
        cookie.SessionFlag = False
        cookie.SaveFoldCookie()
    End Sub
    '结束当前人员在线对话会话
    <WebMethod()> _
    Public Sub ifChatClose(ByVal empid As Integer, ByVal chatid As Integer)
        If chatid > 0 Then
            ioSet.DataDel("ifChatEmp", "EmpID", empid, " and chatid=" & pf.SafeSql(chatid.ToString))
        End If
    End Sub
    '关闭浏览器时做清空操作
    <WebMethod()> _
    Public Sub SignOut(ByVal SessionID As String)
        Dim Log As Integer = 1
        If Not HttpContext.Current Is Nothing Then
            If Log = 1 And ioCom.Profile("PwdPolicy", "StrongLog") = "1" Then '启用强日志,退出系统写日志
                Dim dt As DataTable
                Dim eid As String
                Dim ename As String
                Dim ip As String
                dt = SqlData.ExecuteDataset(ioCom.ConnectString, CommandType.Text, "select * from ssLogInfo where SessionID='" + SessionID + "'").Tables(0)
                If dt.Rows.Count = 1 Then
                    eid = dt.Rows(0)("LoginID").ToString
                    ename = dt.Rows(0)("UserName").ToString
                    ip = dt.Rows(0)("LoginIP").ToString
                    ioSet.ssActLogAdd(ename, "退出系统", "登录表", "", ip, eid, 1, 1)
                End If
            End If
            '清除会话变量,关闭联接记录
            SqlData.ExecuteNonQuery(ioCom.ConnectString, "ssLoginSessionClose", SessionID)
            '清除配置缓存
            pf.RemoveCache("EmpProfile" & SessionID)

            '标示已注销
            System.Web.Security.FormsAuthentication.SignOut()
            HttpContext.Current.Session.Clear()
            HttpContext.Current.Session.Abandon()
            Try
                Dim iNum As Integer
                Dim sql As String
                sql = "select count(sessionid) "
                sql &= " from ssloginfo WITH(NOLOCK) "
                sql &= " where status=1 and not(empid is null)"
                iNum = SqlData.ExecuteScalar(ioCom.ConnectString, CommandType.Text, sql)
                ioCom.OnLineNum = iNum
            Catch ex As Exception
            End Try
        End If

    End Sub

End Class
posted @ 2009-06-10 11:31  嘉应子  阅读(1083)  评论(0编辑  收藏  举报