asp网页怎么写web访问日志

 我来答
缘Lai如茨
2016-05-25 · TA获得超过8630个赞
知道大有可为答主
回答量:7534
采纳率:92%
帮助的人:624万
展开全部
''' <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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式