From 3d15781ad7e2f8692f13972951960bc33cb4d560 Mon Sep 17 00:00:00 2001 From: Elivo Date: Wed, 12 Aug 2020 22:56:52 +0800 Subject: [PATCH] =?UTF-8?q?Apewer-6.0.4=EF=BC=9A=E4=BF=AE=E6=AD=A3=20GetCl?= =?UTF-8?q?ientIP=20=E5=8F=82=E6=95=B0=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/Apewer.csproj | 2 +- Apewer/Web/WebUtility.cs | 23 +++++++++++++---------- Apewer/_ChangeLog.md | 3 +++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Apewer/Apewer.csproj b/Apewer/Apewer.csproj index baaf37f..ce7da5c 100644 --- a/Apewer/Apewer.csproj +++ b/Apewer/Apewer.csproj @@ -14,7 +14,7 @@ netstandard2.1;net20;net40;net461;netcoreapp3.1 Apewer Apewer Libraries - 6.0.3 + 6.0.4 diff --git a/Apewer/Web/WebUtility.cs b/Apewer/Web/WebUtility.cs index 9278f21..53658b5 100644 --- a/Apewer/Web/WebUtility.cs +++ b/Apewer/Web/WebUtility.cs @@ -149,17 +149,20 @@ namespace Apewer.Web #endif { if (request == null) return null; - var direct = GetDirectIP(request); - var x_forwarded_for = GetForwardedIP(request); + var d = GetDirectIP(request); + var f = GetForwardedIP(request); - if (string.IsNullOrEmpty(direct)) - { - return string.IsNullOrEmpty(x_forwarded_for) ? "NULL" : $"{x_forwarded_for},NULL"; - } - else - { - return string.IsNullOrEmpty(x_forwarded_for) ? $"{direct}" : $"{x_forwarded_for},{direct}"; - } + // return string.IsNullOrEmpty(f) ? "NULL" : $"{f},NULL"; + // return string.IsNullOrEmpty(f) ? $"{d}" : $"{f},{d}"; + + // 没有代理,返回 Direct IP。 + if (string.IsNullOrEmpty(f)) return d; + + // 有代理,先加入 Forwarded IP,再加入 Direct IP。 + var ip = f; + if (withProxy && !string.IsNullOrEmpty(d)) ip = ip + "," + d; + + return ip; } /// 请求来自于可信客户端。 diff --git a/Apewer/_ChangeLog.md b/Apewer/_ChangeLog.md index efc5e18..af1f51c 100644 --- a/Apewer/_ChangeLog.md +++ b/Apewer/_ChangeLog.md @@ -5,6 +5,9 @@ ### 最新提交 +### 6.0.4 +- 修正 GetClientIP 参数不生效的问题。 + ### 6.0.3 - 修正 GetParameter 获取不到 GET 参数的问题。