From e3239b71685457791b5e94961867754b47c79515 Mon Sep 17 00:00:00 2001 From: "yidi.wu" Date: Tue, 26 Dec 2023 14:07:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96IP=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 北京北汽/SCP/Business/PageBase.cs | 50 ++++++++++++++++++++- 北京北汽/SCP/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/北京北汽/SCP/Business/PageBase.cs b/北京北汽/SCP/Business/PageBase.cs index fb3892f..267b16e 100644 --- a/北京北汽/SCP/Business/PageBase.cs +++ b/北京北汽/SCP/Business/PageBase.cs @@ -585,7 +585,7 @@ namespace SCP } DateTime now = DateTime.Now; online.User = user; - online.IPAdddress = GetExternalIpAddress();//Request.UserHostAddress; + online.IPAdddress = GetIp4Address(); // GetExternalIpAddress();//Request.UserHostAddress; online.LoginTime = now; online.UpdateTime = now; @@ -2050,6 +2050,54 @@ namespace SCP return partCodeList; } + private static string GetClientIpAddress() + { + string resultIp = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + if (null == resultIp || resultIp == String.Empty) + { + resultIp = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; + } + + if (null == resultIp || resultIp == String.Empty) + { + resultIp = HttpContext.Current.Request.UserHostAddress; + } + return resultIp; + } + + private static string GetIp4Address() + { + string IP4Address = String.Empty; + + if (HttpContext.Current != null) + { + foreach (IPAddress IPA in Dns.GetHostAddresses(GetClientIpAddress())) + { + if (IPA.AddressFamily.ToString() == "InterNetwork") + { + IP4Address = IPA.ToString(); + break; + } + } + } + + if (IP4Address != String.Empty) + { + return IP4Address; + } + + foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) + { + if (IPA.AddressFamily.ToString() == "InterNetwork") + { + IP4Address = IPA.ToString(); + break; + } + } + + return IP4Address; + } + public string GetExternalIpAddress() { try diff --git a/北京北汽/SCP/Properties/AssemblyInfo.cs b/北京北汽/SCP/Properties/AssemblyInfo.cs index 134d7fb..ae64f57 100644 --- a/北京北汽/SCP/Properties/AssemblyInfo.cs +++ b/北京北汽/SCP/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用 "*": -[assembly: AssemblyVersion("1.23.1225.1")] -[assembly: AssemblyFileVersion("1.23.1225.1")] +[assembly: AssemblyVersion("1.23.1226.1")] +[assembly: AssemblyFileVersion("1.23.1226.1")]