本文實例講述了asp.net獲取真實ip的方法。分享給大家供大家參考。具體如下:
public string getip() { 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; }
希望本文所述對大家的asp.net程序設計有所幫助。