猿问

获取客户端IP

网站放到外网如何获取访问的客户端IP呢?请大家支支招吧,谢啦!

慕虎7371278
浏览 615回答 2
2回答

至尊宝的传说

public static string GetClientIP()         {            string clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];            if (string.IsNullOrEmpty(clientIP))                 clientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];            if (string.IsNullOrEmpty(clientIP))                 clientIP = HttpContext.Current.Request.UserHostAddress;            if (string.IsNullOrEmpty(clientIP))                 clientIP = "0.0.0.0";            return clientIP;         }

蓝山帝景

Request.UserHostAddress
随时随地看视频慕课网APP
我要回答