views:

86

answers:

3

I have a website where I want keep track of the Statistics about the users who came to my page from different sources. I want to identify whether user came from Search engines / other websites / direct typing the URL. I am using asp.net and C#. Please help

A: 

As Abdel suggests in his comment, the easiest solution would be to use Google Analytics or a similar tool.

If you really want to do this yourself you should look at the HttpRequest type. This is available in your code through the Page.Request property. The request has a property for UrlReferrer that tells you the url of the page that linked to this one.

Edit: You should be aware that the UrlReferrer may not have the information you need. If the user is sent to your page using a Javascript function you may not get a referrer. Also it will be a lot of work to extract really useful information yourself, so the best option is still to use a thrid-party tool like Google Analytics.

Rune Grimstad
I need to do it myself without third party analytics.The urlreferrer object always returns me null.
Ajay
There are many situations where the UrlReferrer will return null: If the page is opened directly and not from a link, if the page is opened from some types of javascript and maybe flash, if you have browser plug-ins that block this function and some more that I can't remember right now
Rune Grimstad
A: 

Then you'll need to check if the referrer is set in the http header; http://en.wikipedia.org/wiki/HTTP_referrer

k_b
A: 

There is a HTTP header which contains this information: HTTP referrer

ewernli