From 8af95a256711404ed0c4b985f4bf3d337a088f58 Mon Sep 17 00:00:00 2001 From: comm5v8 Date: Sat, 11 May 2019 19:27:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Nignx=E5=8F=8D=E5=90=91?= =?UTF-8?q?=E4=BB=A3=E7=90=86IP=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Common/Utils.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs index d97724b..124ff62 100644 --- a/COMCMS.Common/Utils.cs +++ b/COMCMS.Common/Utils.cs @@ -687,6 +687,12 @@ namespace COMCMS.Common public static string GetIP() { string userHostAddress = MyHttpContext.Current.Request.HttpContext.Connection.RemoteIpAddress.ToString(); + //2019-05-11 增加反向代理获取真实IP + string xForwardedForAddress = MyHttpContext.Current.Request.Headers["X-Forwarded-For"]; + if (!string.IsNullOrEmpty(userHostAddress) && !string.IsNullOrEmpty(xForwardedForAddress) && userHostAddress != xForwardedForAddress) + { + return xForwardedForAddress; + } if (!string.IsNullOrEmpty(userHostAddress) && Utils.IsIP(userHostAddress)) { if (userHostAddress == "::1")