为了账号安全,请及时绑定邮箱和手机立即绑定

获取客户端IP

获取客户端IP

慕虎7371278 2018-07-26 09:10:25
网站放到外网如何获取访问的客户端IP呢?请大家支支招吧,谢啦!
查看完整描述

2 回答

?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

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;
        }


查看完整回答
反对 回复 2018-07-30
?
蓝山帝景

TA贡献1843条经验 获得超7个赞

Request.UserHostAddress

查看完整回答
反对 回复 2018-07-30
  • 2 回答
  • 0 关注
  • 573 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信