在.NET中,WebService和WebForm页面,使用了不同的获得客户IP方法。
注:以下方法在.NET2.0上测试通过。
Web Service使用(通过HttpContext对象调用Request对象):
HttpContext.Current.Request.UserHostAddress
HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_ADDR")[0]
Web Form使用(可直接使用Request对象):
Request.ServerVariables.GetValues("REMOTE_ADDR")[0]
HttpContext.Current.Request.UserHostAddress