Get IP or web visitor's location

I have the following codes to locate our website visitor's location. and I think the code below is only reading to our server's location.
It works but I do not think this is something we can get web visitor's current location.

My question is:
1. Above statement. do you think it is right?
2. Do you know any ways I can find our website visitor's current location regardless it is on mobile or PC?  I understood there is some proxy or some router may not indicate the current location. That is something I can live with. But I do need some ways to get their location instead of just our server address.



  public static Domain.IpInfo GetCurrentPosition()
        {
            //https://ipinfo.io/developers/replacing-getcurrentposition
            Domain.IpInfo ipInfo = new Domain.IpInfo();
            try
            {
                string info = new WebClient().DownloadString("http://ipinfo.io/geo");
                ipInfo = JsonConvert.DeserializeObject<Domain.IpInfo>(info);

                RegionInfo myRI1 = new RegionInfo(ipInfo.Country);
                ipInfo.Country = myRI1.EnglishName;

                RegionInfo myCity = new RegionInfo(ipInfo.City);
                ipInfo.City = myCity.EnglishName;

                RegionInfo myState = new RegionInfo(ipInfo.Region);
                ipInfo.Region = myState.EnglishName;

                RegionInfo myZip = new RegionInfo(ipInfo.Postal);
                ipInfo.Postal = myZip.EnglishName;

                RegionInfo myLoc = new RegionInfo(ipInfo.Loc);
                ipInfo.Loc = myLoc.EnglishName;            
            }
            catch (Exception)
            {
               // ipInfo = null;
            }

            return ipInfo;
        }

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerIT ManagerCommented:
1. Your code is indeed for your server's location only.
2. Slightly adjust your code to do the lookup for HttpContext.Current.Request.UserHostAddress
Then pass it on to the website using the steps detailed here: https://ipinfo.io/developers
Obviously, no one gets work done for free, so you should check if you're will to pay for it: https://ipinfo.io/pricing (cheapest is 250K lookups for some 41 bucks per month)
As you noted, in some cases, you'll get the IP nr of a proxy/VPN service, and even if the visitor DIDN'T actively used anything to hide, some IP nr's just don't have a known location, and a rough estimate is used (sometimes even 50km off)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
change to HttpContext.Current.Request.UserHostAddress won't help. it returns ::1
I have been using ipinfo already.
KimputerIT ManagerCommented:
Please test the code, with the browser on your phone or other laptop/workstation. If you test it on the server, with the browser of the same server, that's what you will get as a result.
ITsolutionWizardAuthor Commented:
I test PC in three different location. the end result is the same
KimputerIT ManagerCommented:
Please show the full page/code
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Mobile

From novice to tech pro — start learning today.