asp网页怎么写web访问日志
1个回答
展开全部
''' <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
''' 初期化
''' </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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询