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
补充:Web开发 , ASP.Net ,