ASP.NET CORE获取客户端IP扩展类

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhu7478848/article/details/83789688
public static class HttpContextExtension
    {
        public static string GetClientUserIp(this HttpContext context)
        {
            var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
            if (string.IsNullOrEmpty(ip))
            {
                ip = context.Connection.RemoteIpAddress.ToString();
            }
            return ip;
        }
    }

猜你喜欢

转载自blog.csdn.net/zhu7478848/article/details/83789688