Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track user activity/actions for an asp.net mvc website?

Tags:

c#

asp.net-mvc

I would like to keep a log of each page view for all users of my web application. After enough time has passed, I will then use that log to generate reports. I would like to have the logging mechanism be a bit flexible since I wouldn't need to log every http request.

An example use case is: A company signs up for my web app and allows 5 employees to use the application. I would like to report that 3 employees used the application in the last week. Or show that 4 employees used it between June and August of the current year.

I'm using asp.net mvc with sql server, if that makes a difference.

Is it just as simple as this? Create a sql table with the following columns: UserId, ControllerName, ActionName, ActionParameters, CreatedOn. Then create an ActionFilterAttribute that adds a record to the db for each action invoked.

Are there any pitfalls that I should worry about (other than a potentially large table size)?

like image 1000
Jim Geurts Avatar asked Oct 03 '09 19:10

Jim Geurts


2 Answers

Some of the pitfalls:

  1. You will not be able to do any server level page caching.
  2. Lots of db writes since you are in effect logging each request.
  3. If there are any actions that happen on pages you could be storing redunant information.

I would assume you would implement this in some type of custom AuthorizeAttribute so your not coding it on every controller but then it will be literally every request which would possibly be more than you actually need.

Have you considered using some type of IIS log parsing utility? It would have a lot of the info you need already.

like image 86
Kelsey Avatar answered Sep 18 '22 18:09

Kelsey


Another option if you are willing to use JavaScript is that you could implement something along the lines of SiteCatalyst. You send a request using JavaScript from the client on page load to a controller action with the appropriate information in the url. eg:

www.example.com\AnalyticsController\Action\currentController\currentAction\userName

The advantage is that your logging is not executed in sequence with all your other operations and you can probably get it working by putting the AJAX call in the master page.

The downside is that it uses JavaScript which as pointed out could be disabled. It would also be really easy to spoof.

like image 21
Dean Johnston Avatar answered Sep 17 '22 18:09

Dean Johnston