看得破的人,处处都是生机;

看不破的人,处处都是困境;

拿得起的人,处处都是担当;

拿不起的人,处处都是疏忽;

放得下的人,处处都是大道;

放不下的人,处处都是迷茫;

想得开的人,处处都是春天;

想不开的人,处处都是凋枯;

做何人,在自己;

小自我,大天地;

asp.net 获取ip的方法

//方法一
HttpContext.Current.Request.UserHostAddress;

//方法二
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

//方法三
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

 

if(Context.Request.ServerVariables["HTTP_VIA"]!=null) // 服务器, using proxy
  {
  得到真实的客户端地址
  ip=Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP.
  }
  else//如果没有使用代理服务器或者得不到客户端的ip not using proxy or can't get the Client IP
  {
  得到服务端的地址
  ip=Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
  }

posted @ 2012-11-01 09:33  心电心  阅读(254)  评论(0编辑  收藏  举报