locked
How can i control my visitor's country? RRS feed

  • Question

  • User-1915193151 posted

    I was create a web services(Ip2Country)

    i send my visitor Ip to this service and return his/her country information(like US|USA|United State of America)

    and it's work correct.

    BUT if our visitor connect useing (vpn or proxy) it does not work correct

     

    sample: 

    Visitor country is germany  but web service return canada or ...(it's return vpn / proxy location)

    How to solve my problem?

    special thanks! :)

    Monday, October 18, 2010 8:34 AM

Answers

  • User1738250506 posted

    If the user uses VPN connection, there is no way, you can detect the original location of the user. The idea behind the VPN is to simulate the user as if he/she is sitting inside the network.

    If the user is using a proxy server, there is a chance but not guaranteed. Some proxies add an extra HTTP header if they are forwarding the request to the server on behalf of some user (http://en.wikipedia.org/wiki/X-Forwarded-For). You can use

    Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

    to detect if the proxy includes this address and use it in the place of "REMOTE_ADDR" value.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 18, 2010 11:57 AM
  • User-952121411 posted

    There is no guarantee you always can get the true source of the request if the request was bounced around servers, but for the most part you should be able to get the country information by the IP.

    The System.Net.Dns namespace exposes a lot of this information. 

    Dns Class:

    http://msdn.microsoft.com/en-us/library/system.net.dns.aspx

    You can get the IP using an ASP.NET server variable like 'REMOTE_ADDR' shown below:

    host = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_ADDR"))

     

    Once you have the IP you can call a free service like the one in the solution below to get back the full details in XML format:

    IP Address Location In ASP.NET:

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=325&AspxAutoDetectCookieSupport=1

    In the above example, the country comes back as a response like below:

    <CountryName>United States</CountryName>


     Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 18, 2010 4:48 PM

All replies

  • User1738250506 posted

    If the user uses VPN connection, there is no way, you can detect the original location of the user. The idea behind the VPN is to simulate the user as if he/she is sitting inside the network.

    If the user is using a proxy server, there is a chance but not guaranteed. Some proxies add an extra HTTP header if they are forwarding the request to the server on behalf of some user (http://en.wikipedia.org/wiki/X-Forwarded-For). You can use

    Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

    to detect if the proxy includes this address and use it in the place of "REMOTE_ADDR" value.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 18, 2010 11:57 AM
  • User-952121411 posted

    There is no guarantee you always can get the true source of the request if the request was bounced around servers, but for the most part you should be able to get the country information by the IP.

    The System.Net.Dns namespace exposes a lot of this information. 

    Dns Class:

    http://msdn.microsoft.com/en-us/library/system.net.dns.aspx

    You can get the IP using an ASP.NET server variable like 'REMOTE_ADDR' shown below:

    host = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_ADDR"))

     

    Once you have the IP you can call a free service like the one in the solution below to get back the full details in XML format:

    IP Address Location In ASP.NET:

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=325&AspxAutoDetectCookieSupport=1

    In the above example, the country comes back as a response like below:

    <CountryName>United States</CountryName>


     Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 18, 2010 4:48 PM
  • User1227478465 posted



    Hello,<o:o:p></o:o:p>



    Considering that many developers in this forum ask how to request
    Location according to IP Address , my team has created a code sample for this
    frequently asked programming task in
    Microsoft All-In-One Code Framework. You
    can download the code samples at:<o:o:p></o:o:p>



    <o:o:p> </o:o:p>



    CSASPNETIPtoLocation<o:o:p></o:o:p>



    http://bit.ly/CSASPNETIPtoLocation<o:o:p></o:o:p>



    With these code samples, we hope to reduce developers’ efforts in
    solving the frequently asked <o:o:p></o:o:p>



    programming tasks. If you have any feedback or suggestions for the
    code samples, please email us:
    onecode@microsoft.com. <o:o:p></o:o:p>



    ------------<o:o:p></o:o:p>



    The Microsoft All-In-One Code Framework (http://1code.codeplex.com) is a free,
    centralized code sample library driven by developers' needs. Our goal is to provide
    typical code samples for all Microsoft development technologies, and reduce
    developers' efforts in solving typical programming tasks.
    <o:o:p></o:o:p>



    Our team listens to developers’ pains in MSDN forums, social media
    and various developer communities. We write code samples based on developers’
    frequently asked programming tasks, and allow developers to
    download them
    with a short code sample publishing cycle. Additionally, our team offers
    a free code sample request service. This
    service is a proactive way for our developer community to obtain code samples
    for certain programming tasks directly from Microsoft.
    <o:o:p></o:o:p>



    Thanks<o:o:p></o:o:p>



    Microsoft All-In-One Code Framework<o:o:p></o:o:p>



    Wednesday, March 23, 2011 4:59 AM