string IP = HttpContext.Request != null ? HttpContext.Request.UserHostAddress : "127.0.0.1";
注:这玩意你在VS上运行LocalHost 不好用,返回的一定是 "::1"
但是放到IIS上应该就好使多了。