日期:2014-05-17 浏览次数:20526 次
if (Request.ServerVariables["HTTP_VIA"] != null) { GuestIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); } else { if (Request.ServerVariables["HTTP_VIA"] != null) { GuestIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); } else { GuestIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); } }
------解决方案--------------------
private string GetClientIP() { string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (null == result || result == String.Empty) { result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (null == result || result == String.Empty) { result = HttpContext.Current.Request.UserHostAddress; } return result; }
------解决方案--------------------