An application that records user access logs on a Sharepoint website based on custom code!

Source: Internet
Author: User

 Commercial Products for website or system user access logs include Google statistics, Baidu statistics, and quantum statistics. These products provide powerful functions and have poor customization, it is difficult to meet personalized needs. This article introduces a definition-basedCodeThis method records access logs of users on a Sharepoint website or system. The component used for user access logs is a user access log developed based on C # In my dissertation more than two years ago. The implementation principle of this component is very simple: the ihttpmodule interface is mainly used in the web. the httpmodule node in config adds the configuration of this component. Considering the performance and portability, the database uses open source SQLite to facilitate maintenance and data collection. The specific implementation steps are as follows:

1. use this user to access the log component if yes.. net. the httpmodule node is added in config, and the other is to create a user access log site, which can be used to record access logs of any website (whether it is. net, PHP, Java, etc.), mainly using a piece of embedded JS Code, the essence of the method is the same as the commercial-level products, considering the performance and independence, this article uses the latter method.

2. Add two sections of js code to the SharePoint page to be counted. One section of JS is used to obtain information about the currently logged-on user, and the other section is used to record access logs.

3. Use the SSIS tool to automatically import user access log database (SQLite) to the log data warehouse (SQL Server) and develop an SQL CLR for URL Decoding.

4. Use SSRs to develop a user access log report and deploy it to the SharePoint website for query.

For example, to add the Log Access record function in excelservicesample. aspx, you can use SharePoint designer to edit it, for example:

Edit excelservicesample. aspx and add the following JavaScript code for Log Access:

<SCRIPT type = "text/JavaScript"> Sp.sod.exe cuteordelayuntilscriptloaded (runmycode, "Sp. js" );  VaR Currentuser = Null  ;  VaR Currentusertitle = Null  ; Function  Runmycode (){  VaR CTX = New  Sp. clientcontext. get_current ();  VaR Web = CTX. get_web (); CTX. Load (Web );  VaR User = Web. get_currentuser (); User. Retrieve (); ctx.exe cutequeryasync (  Function  (){  // Only in the success case you can work with user login  Currentuser = User. get_loginname (); currentusertitle = User. get_title (); document. getelementbyid ( "Randimg"). src = "http: // 10.30.99.118: 8081/default. aspx? Username = "+ currentuser +" & usertitle = "+ Currentusertitle ;},  Function  (Data ){  //  Verify y the failure  });} </SCRIPT> 

Save and publish, for example:

Access this page and test whether the access log has been recorded, for example:

If the record is successful, the corresponding log database will be automatically created at the Log Access record site, for example:

You can connect to the database in vs to check whether the database has been recorded, for example:

You can see in urlabsoluteuri that the URL in JS has been recorded, for example:

You can see in urlreferrerabsoluteuri that the real URL for accessing the page, such:

Set up a log access record website, such:

 

Test another record page. For example, to add the Log Access record function in default. aspx, you can use SharePoint designer to edit and add JS Code, such:

Open default. aspx and test whether the access log has been recorded, for example:

View the log database in vs. the logs on the default page have been recorded, for example:

Develop an SQL clr function for URL programming: sqlserverproject and register it with SQL Server:

 

 Exec Sp_changedbowner '  SA  '   Go  --  Enable database CLR support  Exec Sp_configure '  Show advanced options  ' , '  1  '  ;  Go  Reconfigure  ;  Go  Exec Sp_configure '  CLR Enabled  ' , '  1  '  Go  --  Change the database trust mode (to be correctly addedProgramSet)  Alter   Database Database Name Set Trustworthy On  Go  Create  Assembly  [ System. Web  ]   From  '  C: \ windows \ Microsoft. NET \ framework64 \ v2.0.50727 \ System. Web. dll  '  With Permission_set =  Unsafe  Go  Create  Assembly SQL _clr_url  From       ' D: \ sqlserverproject. dll  '      With Permission_set =  Unsafe  Go  Create   Function   [  DBO  ] . [  Sqlurldecode  ] ( @ Urlstr  Nvarchar ( 4000  ))  Returns   Nvarchar ( 4000  )  As  External name SQL _clr_url.userdefinedfunctions.sqlurldecode  Go  Create   Function   [  DBO  ] .[  Sqlurlencode  ] ( @ Urlstr   Nvarchar ( 4000  ))  Returns   Nvarchar ( 4000  )  As  External name SQL _clr_url.userdefinedfunctions.sqlurlencode  Go 

 

The execution is successful, for example:

 

Develop a Log Access statistics report, such:

Click to view log details, such:

After the preceding steps, the user access log function of the SharePoint website or system is simple and can be expanded as needed to meet Personalized Requirements.

My Log Access logging component is open source, welcome to download: http://uservisitlogshelp.codeplex.com/

this blog is original software life, welcome to reprint, reprint please indicate the source: http://www.cnblogs.com/nbpowerboy/archive/2013/06/12/3133169.html. Assume or use it for commercial purposes, but you must keep the signed software life (including links) in this article ). If you have any questions or authorization negotiation, please leave a message for me. SharePoint Business Intelligence Technology QQ group: 140668362,. NET technology exchange QQ group: 195516928, welcome to join the discussion .

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.