增加Nignx反向代理IP识别

This commit is contained in:
comm5v8
2019-05-11 19:27:29 +08:00
parent b89fb01eeb
commit 8af95a2567
+6
View File
@@ -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")