WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Sunday, June 14, 2009

ASP.NET IP Address behind Proxy

While working on a Project where we needed to submit a monthly report to our clients which included the number of Clicks and number of Unique users, we always ended up having about 10-20% discrepancies when it was compared with the clients internal reports. Most of our clients were using Atlas tracking (Microsoft’s product) which made us rethink the blame game. So one of our clients was kind enough to send us their internal report and we realized that they had more unique IP users (like 20% more users IP) logged than we did. So while brainstorming our code we found that we missed to code the obvious scenario when the User’s are behind a proxy server like computers within a office n/w share the same IP.
Using Request.ServerVariables[“REMOTE_ADDR”] was only logging the Proxy address and not the actual clients IP. So we had to modify our code to the following:



"HTTP_X_FORWARDED_FOR" request variable for the most part has the actual clients address but we need to make sure the variable is not null or empty. Thus the conditional check.

Labels: ,