public static string GetUserIp(this HttpContext httpContext) { #if NET40 string userIp = httpContext.Request.UserHostAddress; #else string userIp = Utils.SafeToString(httpContext.Connection.RemoteIpAddress); #endif return(userIp); }
public static string GetUserIp(this HttpContext httpContext) { #if NET452 string userIp = httpContext.Request.UserHostAddress; #else string userIp = Utils.SafeToString(httpContext.Connection.RemoteIpAddress); #endif string xForwardedFor = httpContext.GetRequestHeader(Constants.HttpHeaderXForwardedFor); if (!string.IsNullOrEmpty(xForwardedFor)) { userIp = xForwardedFor + ", " + userIp; } return(userIp); }