获取IP地址的问题 [英] problem to get the IP address
本文介绍了获取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();
这篇关于获取IP地址的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文