mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
28 lines
1.0 KiB
1 year ago
|
|
||
|
using System.Linq;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
||
|
public class BaseController : Controller
|
||
|
{
|
||
|
protected string GetRequestIP()
|
||
|
{
|
||
|
string ip = null;
|
||
|
|
||
|
if (Request.HttpContext?.Request?.Headers != null && Request.HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
|
||
|
{
|
||
|
var forwardedip = Request.HttpContext.Request.Headers["X-Forwarded-For"].ToString();
|
||
|
ip = forwardedip.TrimEnd(',').Split(",").Select(s => s.Trim()).FirstOrDefault();
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(ip) && Request.HttpContext?.Connection?.RemoteIpAddress != null)
|
||
|
ip = Request.HttpContext.Connection.RemoteIpAddress.ToString();
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(ip) && Request.HttpContext?.Request?.Headers != null && Request.HttpContext.Request.Headers.ContainsKey("REMOTE_ADDR"))
|
||
|
{
|
||
|
var remoteip = Request.HttpContext.Request.Headers["REMOTE_ADDR"].ToString();
|
||
|
ip = remoteip.TrimEnd(',').Split(",").Select(s => s.Trim()).FirstOrDefault();
|
||
|
}
|
||
|
|
||
|
return ip;
|
||
|
}
|
||
|
}
|