asp.net开发的web系统,记录简单LOG的方法

asp.net开发的web系统,记录简单LOG(什么时间哪个用户访问了什么页面,点击了什么按钮)的方法

页面效果:

 

相关代码:

    ''' <summary>
    ''' 初期化
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

         。。。

        '写操作log
        LogInfo.writeLogInfo(Me)
    End Sub

 


    Public Shared Sub writeLogInfo(ByVal myPage As System.Web.UI.Page)
        Dim userID As String
        Dim userName As String
        Dim keyDateTime As String
        Dim kb As String
        Dim formID As String
        Dim formName As String
        Dim buttonID As String
        Dim buttonName As String
        Dim c As WebControls.Button
        Dim iIndex As Integer

        Try
            userID = CType(myPage.Session(ConstantInfo.SESSION_USER_INFO_CONST), UserInfoEntity).UserID
            userName = CType(myPage.Session(ConstantInfo.SESSION_USER_INFO_CONST), UserInfoEntity).UserName
            keyDateTime = Format(Now, "yyyy-MM-dd HH:mm:ss")
            If Not myPage.IsPostBack Then
                kb = "1"     '画面
                iIndex = myPage.AppRelativeVirtualPath.LastIndexOf("/")
                If iIndex <> -1 Then
                    formID = myPage.AppRelativeVirtualPath.Substring(iIndex).Replace("/", "")
                Else
                    formID = myPage.AppRelativeVirtualPath
                End If
                formName = myPage.Title
                buttonID = "-"
                buttonName = ""

                '插入到LOG表
                insertLogTable(userID, userName, keyDateTime, kb, formID, formName, buttonID, buttonName)
            Else
                kb = "2"     '按钮

                iIndex = myPage.AppRelativeVirtualPath.LastIndexOf("/")
                If iIndex <> -1 Then
                    formID = myPage.AppRelativeVirtualPath.Substring(iIndex).Replace("/", "")
                Else
                    formID = myPage.AppRelativeVirtualPath
                End If
                formName = myPage.Title
                c = getPostBackControlID(myPage)
                If Not c Is Nothing Then
                    buttonID = c.ID
                    buttonName = c.Text

                    '插入到LOG表
                    insertLogTable(userID, userName, keyDateTime, kb, formID, formName, buttonID, buttonName)
                End If
            End If
        Catch ex As Exception
            'do nothing
        End Try

    End Sub

 
    Private Shared Function getPostBackControlID(ByVal myPage As System.Web.UI.Page) As WebControls.Button
        Dim ctrl As Control = Nothing
        Dim ctrlName As String = myPage.Request.Params("__EVENTTARGET")

        If Not ctrlName Is Nothing AndAlso Not ctrlName.Equals("") Then
            ctrl = myPage.FindControl(ctrlName)
        Else
            Dim ctrlStr As String = ""
            Dim c As Control = Nothing

            For Each ctl As String In myPage.Request.Form
                If ctl.EndsWith(".x") OrElse ctl.EndsWith(".y") Then
                    ctrlStr = ctl.Substring(0, ctl.Length - 2)
                    c = myPage.FindControl(ctrlStr)
                Else
                    c = myPage.FindControl(ctl)
                End If
                If TypeOf (c) Is System.Web.UI.WebControls.Button Then
                    ctrl = c
                    Exit For

                End If
            Next
        End If

        Return ctrl
    End Function

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值