📜  客户端机器IIS的asp net saber ip地址 - C#代码示例

📅  最后修改于: 2022-03-11 14:48:53.784000             🧑  作者: Mango

代码示例1
///  /// Get current user ip address. ///  /// The IP Address public static string GetUserIPAddress() { var context = System.Web.HttpContext.Current; string ip = String.Empty; if (context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) ip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); else if (!String.IsNullOrWhiteSpace(context.Request.UserHostAddress)) ip = context.Request.UserHostAddress; if (ip == "::1") ip = "127.0.0.1"; return ip; }