first commit
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user