adjust extensions, again and again

This commit is contained in:
rootdarkarchon
2023-02-10 15:18:34 +01:00
parent 03d7549d29
commit 3490c5c8d8

View File

@@ -4,7 +4,10 @@ namespace MareSynchronosShared;
public static class Extensions
{
private static long _noIpCntr = 0;
public static string GetIpAddress(this IHttpContextAccessor accessor)
{
try
{
if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"]))
return accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"];
@@ -26,6 +29,11 @@ public static class Extensions
}
}
return accessor.HttpContext.Connection.RemoteIpAddress.ToString();
return accessor.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "NoIp";
}
catch
{
return "NoIp" + _noIpCntr++;
}
}
}