tags:

views:

249

answers:

2

Hi

I am working on a asp.net application in which i am creating a page which tracks user activity like no of page visited in my application.

In which i also need to found out the Total KB (data) received since log in and the total KB (data) sent since log in by each user.

How can i achieve this?

+1  A: 

Firstly, I'd consider whether you need to implement this functionality yourself, Google Analytics does a good job of tracking usage and is free. You can find it on http://www.google.com/analytics, all you need to do is add a bit of javascript to all your pages. Your master page is a good place to do this.

If you're hellbent on doing this yourself, a good way to implement this is to use an HttpModule. An HttpModule gets invoked during every page request.

In the Init method of your HttpModule you can catch the BeginRequest and EndRequest events. You can look at the Request object in BeginRequest and the Response object in EndRequest. You can find the amount of data sent in the ContentLength property. You'll need to store whatever information you're after in a database. On the page that displays user activity, you'd simply retrieve these values from your database.

I'd seriously contemplate using Google Analytics though.

Mark Worth
Hi Mark, Thanks for this information. I did tried the httpmodule solution but the contentlength property is there only for request object and not for response object.
A: 

The question doesn't actually clarify what is encompassed in the "Total Data Sent/Received". While an HttpModule would help you with aspx output, it wouldn't include the size of images, css, js, etc files. While I'm not sure why he'd want this, it falls outside Google Analytics capabilities.

I guess an HTTPModule could do it (?) IF you mapped ALL resource types to be handled by the .NET framework, so you could 'measure' the size of all the different files as you served them. By tracking the login cookie (or whatever you use) it might be easy to write all this data to a database and report on it in close-to-real-time (could be slow though).

The obvious place that bytes sent/received is stored is the IIS logfiles. Using LogParser would enable you to report on that data - probably if you write a session cookie (or track IP addresses, or something else) you could link that data up to each individual user login. Pretty much impossible to do in 'real time' though, based just on IIS logs.

Another developer's project that I've seen which might help you is Matt Berseth's 'openurchin' and LiveTraffic page- his example uses a javascript like Google Analytics, but sends data back to you. You will need to write code to parse/save the data yourself, including figuring out the bytes sent/received info.

Perhaps if you provided more information on what you are trying to accomplish we could offer better solutions? Google Analytics is awesome at what it does; and provides detailed reports on page visits, entries, exits, unique users, etc - very visual reports and easy to use. Doesn't really go down to "user level" though. So it all depends on what you need to do...

CraigD
Hi Craig, Thanks for this information We are not going to use Google Analytics due to some reason. In my page i will be showing other details like each user visited ip address , no of pages visited etc with data sent/received details by each user.i need to confirm should i need to include size of images,css etc but the final aim is to judge the load on the server.hope i have cleared my question to sum extend.