我获取客户端地址 在本地测试是好錒 但服务器上却获取到自己服务器地址了
是什么原因錒,大家帮我看下···
我获取IP的2种方法:
1. public static string GetIPAddress()
{ string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
2.info.IP = this.Page.Request.UserHostAddress.ToString();
是什么原因錒,大家帮我看下···
我获取IP的2种方法:
1. public static string GetIPAddress()
{ string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
2.info.IP = this.Page.Request.UserHostAddress.ToString();
http://www.cnblogs.com/cnaspnet/archive/2008/07/05/1236181.html
{
string ipAddress;
string http_x_forwarded_for = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (http_x_forwarded_for == null || http_x_forwarded_for == "" || http_x_forwarded_for.IndexOf("unknown") > 0)
{
ipAddress = request.ServerVariables["REMOTE_ADDR"];
}
else if (http_x_forwarded_for.IndexOf(",") > 0)
{
ipAddress = http_x_forwarded_for.Substring(0, http_x_forwarded_for.IndexOf(",") - 1);
}
else if (http_x_forwarded_for.IndexOf(";") > 0)
{
ipAddress = http_x_forwarded_for.Substring(0, http_x_forwarded_for.IndexOf(";") - 1);
}
else
{
ipAddress = http_x_forwarded_for;
}
return ipAddress;//.Substring(1,30);
}