27 lines
895 B
C#
27 lines
895 B
C#
using System.Linq;
|
|
using System.Net;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Landmark.OLA.Models.Loan;
|
|
|
|
namespace Landmark.OLA.Application.Common.Security
|
|
{
|
|
public static class ForwardedHeaderService
|
|
{
|
|
public static string GetRemoteIPAddress(HttpContext context)
|
|
{
|
|
var header = (context.Request.Headers["CF-Connecting-IP"].FirstOrDefault() ?? context.Request.Headers["X-Forwarded-For"].FirstOrDefault());
|
|
if (IPAddress.TryParse(header, out IPAddress ip))
|
|
{
|
|
return ip.ToString();
|
|
}
|
|
return context.Connection.RemoteIpAddress.ToString();
|
|
}
|
|
|
|
public static LoanContainer AppendIPAddress(LoanContainer loanContainer, HttpContext context)
|
|
{
|
|
loanContainer.LoanApplication.IPAddress = GetRemoteIPAddress(context);
|
|
return loanContainer;
|
|
}
|
|
}
|
|
}
|