c# - how to find the ip address of client who is login to our website or browsing our website -


here have small problem, want find out ip address of client accessing website, tried many these giving me 127.0.0.1 ip, while testing in local host,

please 1 provide code snippet , me,

thanks in advance,

 public string getclientip() {     string result = string.empty;     string ip = httpcontext.current.request.servervariables["http_x_forwarded_for"];     if (!string.isnullorempty(ip))     {         string[] iprange = ip.split(',');         int le = iprange.length - 1;         result = iprange[0];     }     else     {         result = httpcontext.current.request.servervariables["remote_addr"];     }      return result; } 

this expected, localhost ip address of time 127.0.0.1.

as said in comments, when deploy site , remote clients access it, actual ip correctly retrieved.

if want try locally, can try configure local network remote computer on same network access web site. there should see ip address of computer (for instance: 192.168.x.x).


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -