MR.ABC
MR.ABC

Reputation: 4862

MVC4 Web Api Client IP

i'm looking for a way to get the client ip address inside controller. I've tried HttpContext.Current.Request.UserHostAddress. This returns me ::1. Right now the Webserver is running on localhost and the requst is from localhost, too. Will this method work after deploying ?

Upvotes: 3

Views: 1348

Answers (1)

Piotr Stapp
Piotr Stapp

Reputation: 19830

Yes it will work.Now it is returing localhost in IP 6 format.

There are only a few things you should remember about:

  1. If user is behind NAT or proxy it will show IP of NAT/proxy
  2. There is a discussion about more problems with wrong IP UserHostAddress gives wrong IPs

Upvotes: 4

Related Questions