asp net saber ip address of client machine IIS code example

Example: asp net saber ip address of client machine IIS

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

Tags:

Misc Example