Tracking users in asp.net
I am working on an asp.net application in which I create a page that tracks user activity such as no page visit in my application.
In that I also need to find out the Total KB (data) received since login and the total KB (data) sent since login by each user.
How can I achieve this?
The question doesn't really clarify what is included in the Sent / Received Totals. Although the HttpModule will help you with the aspx output, it will not contain the size of the images, css, js, etc. Files. While I'm not sure why he would want it, it goes beyond the capabilities of Google Analytics.
I think the HTTPModule could do this (?) 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 they are served. By tracking the login cookie (or whatever you use), it can be easy to write all of that data to the database and report it in real time (maybe slower though).
The obvious place where the number of bytes sent / received is stored is the IIS log file. Using a LogParser will allow you to report this data - perhaps if you write a session cookie (or track IP addresses or whatever) you can associate this data with each user. Almost impossible to do in real time based on IIS logs alone.
Another developer project I've seen that can help you is Matt Berseth 'openurchin' and the LiveTraffic Page - his example uses javascript like Google Analytics but is sent back to you. You will need to write code to parse / save the data yourself, including figuring out the transmitted / received bytes of information.
Perhaps if you could provide more information on what you are trying to achieve, we could suggest better solutions? Google Analytics is amazing at what it does; and provides detailed reports on page visits, entries, exits, unique users, etc. - very visual reports and easy to use. However, it doesn't really go to the "user level". So it all depends on what you need to do ...
a source to share
First, I would have wondered if you need to implement this functionality yourself, Google Analytics does a good job of tracking usage and is free. You can find it at http://www.google.com/analytics , all you have to do is add some javascript to all your pages. Your home page is a good place to do this.
If you are doing this yourself, a good way to do this is to use an HttpModule. The HttpModule is called 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 the BeginRequest and the Response object in the EndRequest. You can find the amount of data sent in the ContentLength property. You will need to store all the information you need in the database. On a page displaying user activity, you simply retrieve these values ββfrom your database.
I would seriously consider using Google Analytics.
a source to share