using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace System.Common { public static class IPHelper { public static string GetIp(this HttpContext context) { var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (string.IsNullOrEmpty(ip)) { ip = context.Connection.RemoteIpAddress.ToString(); } return ip; } } }