日期:2014-05-17  浏览次数:20415 次

怎么获取用户登录的IP地址???
我想记录用户操作IP地址
  怎么获取??
一:this.Page.Request.UserHostAddress.ToString();
二: 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;
  }
还有什么方法,获取最真实的IP地址



------解决方案--------------------
string ip = Request.ServerVariables["Remote_Addr"];
string ip = Request.UserHostAddress;
------解决方案--------------------
探讨
我想记录用户操作IP地址
  怎么获取??
一:this.Page.Request.UserHostAddress.ToString();
二: public static string GetIPAddress()
{

string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.S……

------解决方案--------------------
知道的也就lz这样的了 
public static string GetIP()
{
string result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
if (string.IsNullOrEmpty(result))
result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (string.IsNullOrEmpty(result))
result = HttpContext.Current.Request.UserHostAddress;

if (string.IsNullOrEmpty(result) || !Utils.IsIP(result))
return "127.0.0.1";

return result;
}
------解决方案--------------------
探讨
string ip = Request.ServerVariables["Remote_Addr"];
string ip = Request.UserHostAddress;

------解决方案--------------------
Request.UserHostAddress.ToString() 就可以获得登录客户的IP地址的
------解决方案--------------------
http://topic.csdn.net/u/20090617/11/8f0432b6-84ee-49da-a55f-86b3d343ab8b.html
------解决方案--------------------
string ip = Request.ServerVariables["Remote_Addr"];
string ip = Request.UserHostAddress