获取IP地址的问题

获取IP地址的问题

问题描述:

尊敬的先生/女士





i创建一个网站。

i想要获取客户端的ipaddress。

i在服务器和两个客户端运行它,但是在标签上显示ip。

但是在所有系统上只显示服务器ip。

i希望看到运行网站的系统的IP。请帮助我

Dear Sir/Ma''am


i create a website .
i want to fetch the ipaddress of the clients.
i run it at server and at two client but ip shown at a label.
but on all the systems only server ip is shown.
i want to see the ip of system at which website is running .Please help me

简单:Request.UserHostAddress返回它:MSDN [ ^ ]
Easy: Request.UserHostAddress returns it: MSDN[^]


嗨!!!

你不要发布你的代码!你可以发贴你使用的和以下代码可以捕获这样的IP地址:







Hi!!!
you don;t post your code !!! can you post the are you using and below code can capture the Ip Address like this:



HttpRequest currentRequest = HttpContext.Current.Request;
      string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

     if (ipAddress == null || ipAddress.ToLower() == "unknown")
          ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

     return ipAddress;





或类似这样





or like this

String ipAddress =
        System.Web.HttpContext.Current.Request.UserHostAddress;





看一下这个链接

http://www.c-sharpcorner.com/uploadfile/krishnasarala/find-client-ip-address-and-location-in-Asp-Net/ [ ^ ]


string ipAddress = Request.ServerVariables["REMOTE_HOST"].ToString();