1.方法一
HttpContext.Request.UserHostAddress
2.方法二
public static string GetClientIp()
{
String clientIP = "";
if (System.Web.HttpContext.Current != null)
{
clientIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(clientIP) || (clientIP.ToLower() == "unknown"))
{
clientIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"];
if (string.IsNullOrEmpty(clientIP))
{
clientIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(clientIP))
{ clientIP = System.Web.HttpContext.Current.Request.UserHostAddress; }
}
else
{
clientIP = clientIP.Split(',')[0];
}
}
return clientIP;
}要放在服务器上才能体现效果 如果是在本机上回得到;;1

京公网安备 11010502036488号