1

i want to get the client IP address who makes the request to my site. here is some code to get this:

 var w2 = HttpContext.Request.UserHostAddress;
 var w3 = this.Request.UserHostAddress;

this works fine when the request comes from browser. but when the request comes from javascript i don't get the results excpected.

here is my javascript requset:

<script src="http://localhost:55866/Dashboard/GetCampine?MediaId=21&ProductsTypId=5 "> 
    </script>

that is what i get: w3=::1 w2=::1

Yitzhak Weinberg
  • 2,324
  • 1
  • 17
  • 21
  • 1
    `::1` Looks like the IPv6 loopback address (local address of your computer), it's the expected value if you are testing on `localhost`. Also you question is probably not about javascript. – Volune Mar 07 '16 at 07:56
  • 1
    It's only when you're testing your code in `localhost` that you're seeing `::1` as the client host (it's the local address of the IPv6 loopback interface). Also, there shouldn't be any difference when the request is initiated by regular / Ajax request (in terms of client info). – haim770 Mar 07 '16 at 07:56
  • It's `localhost` for IPv6. Please see [this answer](http://stackoverflow.com/questions/6408957/request-userhostaddress-issue-with-return-result-1). – Uladzimir Palekh Mar 07 '16 at 07:57

0 Answers0