Click to See Complete Forum and Search --> : How to track web page usage


smc7
07-08-2009, 11:53 AM
I'm quite new to ASP.NET and C# and have been asked to come up with a way to track web page usage for the ASP & ASP.NET pages on our site. Most everything has been converted to ASP.NET, but there still are some ASP apps out there.

I have spent several days searching the web with little success of finding anything that will explain what they are doing and how to set it up; found plenty that are not for beginners and left me discouraged.

Would like to capture into SQL SERVER:
1). How many times a page has been accessed 2). Name of Page being accessed 3). Who is accessing the page 4). What date the page was accessed by individual 5). I.P. of user

LiteTest
07-12-2009, 06:53 PM
This is quite a simple one really, however let me start by mentioning a few things:
These things should already exist in the server logs, and if you can be flexible with your data you can always use google analytics for free.

Now, if you do want to proceed and do this on your site and store the data localy, this is how I would go about it.

Create a table in Sql that contains the fields you need:
Page_Count
Page_Name
Accessed_By (this would only work for registered users on your site since you can't get unique identifiers for your visitors, unless you rely on cookies and they can be deleted from the browser, but if you don't care about cookies going missing, use Guid.NewGuid() for cookie value)
Date_Accessed as a datetime field
and lastly: User_Ip

Now, to get the user ip in .Net:
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]

Create a custom page class that inherits from System.Ui.Page
For every hit to the page, create a new object containing all the values, and then store them in the database.
You can get the name of the page using the Request.Url object

When you want to see the number of hits to a certain page, you can just run a select count(*) from your_table_name where page_name = 'name of your page'

sknake
07-16-2009, 05:15 AM
I would recommend that you parse the IIS log files and calculate usage metrics after you have completed the import. There is a free reporting application for single-sites called "Smarter Stats" that can give you an idea of usage reporting.

textbox
07-29-2009, 08:20 PM
I would recommend using google analytics. This is a free service as already mentioned and will provide you with more detail than you probably need. Logging everything to a sql server is going to add unnecessary overhead to each of your applications.