c# 获取客户端IP
程序员文章站
2022-12-25 12:09:16
/// /// 获得当前页面客户端的IP /// /// 当前页面客户端的IP public static string GetIP() { try { string result = String.Empty; ... ......
/// <summary> /// 获得当前页面客户端的ip /// </summary> /// <returns>当前页面客户端的ip</returns> public static string getip() { try { string result = string.empty; result = httpcontext.current.request.servervariables["http_x_forwarded_for"]; if (string.isnullorempty(result)) { result = httpcontext.current.request.servervariables["remote_addr"]; } if (string.isnullorempty(result)) { result = httpcontext.current.request.userhostaddress; } if (string.isnullorempty(result) || !utils.isip(result)) { return "127.0.0.1"; } return result; } catch (exception ex) { system.diagnostics.trace.write(ex.message); return httpcontext.current.request.userhostaddress; } }
下一篇: 从内到外为电竞而生 ROG游戏手机评测