move shared content to shared project

This commit is contained in:
rootdarkarchon
2022-08-22 11:21:28 +02:00
parent 927e1aaceb
commit 6c243d0247
40 changed files with 117 additions and 97 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Http;
using System.Linq;
namespace MareSynchronosServer
{
public static class Extensions
{
public static string GetIpAddress(this IHttpContextAccessor accessor)
{
if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"]))
return accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"];
if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["X-Forwarded-For"]))
{
return accessor.HttpContext.Request.Headers["X-Forwarded-For"];
}
var ipAddress = accessor.HttpContext.GetServerVariable("HTTP_X_FORWARDED_FOR");
if (!string.IsNullOrEmpty(ipAddress))
{
var addresses = ipAddress.Split(',');
if (addresses.Length != 0)
return addresses.Last();
}
return accessor.HttpContext.Connection.RemoteIpAddress.ToString();
}
}
}