获取客户端ip地址
public static string GetIP()
{
Microsoft.AspNetCore.Http.HttpContext httpContext = HttpContext.Current;
var ip = httpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip))
{
ip = httpContext.Connection.RemoteIpAddress.ToString();
if (ip == "::1")
ip = httpContext.Connection.LocalIpAddress.ToString();
}
return ip;
}