A simple LOG method for a web system developed by asp.net

Source: Internet
Author: User

The web system developed by asp.net records the method page of simple LOG (when and when the user accessed the page and clicked the button). Effect: related code: ''' <summary> ''' initially ''' </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... 'Write operation 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" 'image 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 = "" 'insert into the LOG table insertLogTable (userID, userName, keyDateTime, kb, formID, formName, buttonID, buttonName) else kb = "2" 'button 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 'insert into the LOG table insertLogTable (userID, userName, keyDateTime, kb, formID, formName, buttonID, buttonName) 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 TypeOf (c) Is System. web. UI. webControls. button Then ctrl = c Exit For End If Next End If Return ctrl End Function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.