網站放到外網如何獲取訪問的客戶端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; }
- 2 回答
- 0 關注
- 650 瀏覽
添加回答
舉報
0/150
提交
取消