From 2f53405c42c22324c52820a6ecdf83c45eadfaa3 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 1 Sep 2021 13:47:15 +0200 Subject: [PATCH] client IP address extension --- zero.Core/Extensions/HttpContextExtensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zero.Core/Extensions/HttpContextExtensions.cs b/zero.Core/Extensions/HttpContextExtensions.cs index 107b0094..2edc77de 100644 --- a/zero.Core/Extensions/HttpContextExtensions.cs +++ b/zero.Core/Extensions/HttpContextExtensions.cs @@ -40,5 +40,16 @@ namespace zero.Core.Extensions return context.Request.Headers["Accept"] == "application/json"; } + + + /// + /// Get IP Address of the client + /// + public static string GetClientIpAddress(this HttpContext context) + { + return context.Connection.RemoteIpAddress?.ToString(); + //string ipAddress = context.GetServerVariable("HTTP_X_FORWARDED_FOR"); + //return !ipAddress.IsNullOrEmpty() ? ipAddress.Split(',')[0] : context.GetServerVariable("REMOTE_ADDR"); + } } }