Soroosh Sharif Soroosh Sharif - 1 year ago 116
ASP.NET (C#) Question

ASP.NET web application visitor counter

I've got a simple web application which I need to keep track of visitors. Each visitor's information is stored in the following table:


| ID | ComputerName | VisitDate | CountryCode | Platform | Browser | BrowserVersion |

is vistor's IP address.

The table contains ipv6 records which causes problems in calculating visitor's count or sometimes causes Token errors.

Is it wise to force visitors to use ipv4?
if yes, how?

Answer Source
    public string IpAddress()
string strIpAddress;
strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIpAddress == null)
strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
return strIpAddress;

foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
if (IPA.AddressFamily.ToString() == "InterNetwork")
IP4Address = IPA.ToString(); 

Please refer below links also: