Browse Source

获取IP方法。

master
yidi.wu 11 months ago
parent
commit
e3239b7168
  1. 50
      北京北汽/SCP/Business/PageBase.cs
  2. 4
      北京北汽/SCP/Properties/AssemblyInfo.cs

50
北京北汽/SCP/Business/PageBase.cs

@ -585,7 +585,7 @@ namespace SCP
} }
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
online.User = user; online.User = user;
online.IPAdddress = GetExternalIpAddress();//Request.UserHostAddress; online.IPAdddress = GetIp4Address(); // GetExternalIpAddress();//Request.UserHostAddress;
online.LoginTime = now; online.LoginTime = now;
online.UpdateTime = now; online.UpdateTime = now;
@ -2050,6 +2050,54 @@ namespace SCP
return partCodeList; 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() public string GetExternalIpAddress()
{ {
try try

4
北京北汽/SCP/Properties/AssemblyInfo.cs

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用 "*": // 方法是按如下所示使用 "*":
[assembly: AssemblyVersion("1.23.1225.1")] [assembly: AssemblyVersion("1.23.1226.1")]
[assembly: AssemblyFileVersion("1.23.1225.1")] [assembly: AssemblyFileVersion("1.23.1226.1")]

Loading…
Cancel
Save