25 lines
630 B
C#
25 lines
630 B
C#
namespace Application.Web;
|
|
|
|
public class ComHelper
|
|
{
|
|
public static string GetClientUserIp(HttpContext context)
|
|
{
|
|
var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
|
if (string.IsNullOrEmpty(ip))
|
|
{
|
|
ip = context.Connection.RemoteIpAddress.ToString();
|
|
ip = ip.Replace("::ffff:", "");
|
|
}
|
|
if (ip.Contains(","))
|
|
{
|
|
ip = ip.Split(',')[0];
|
|
}
|
|
//var ip = context.Request.Cookies["kxUserIp"];
|
|
//if (string.IsNullOrEmpty(ip))
|
|
//{
|
|
// ip = "0.0.0.0";
|
|
//}
|
|
|
|
return ip;
|
|
}
|
|
} |