I'm running an ASP.NET Core MVC app on AWS in an Elastic Beanstalk environment that includes ELB.
I use this code to get the IP address of the client:
HttpContext.Connection.RemoteIpAddress.ToString()
However, this returns the IP address of the load balancer, not the IP address of the client. I believe RemoteIPAddress
returns the address stored in the X-Forwarded-For HTTP header, which in theory should be the client IP, but it isn't.
So I followed the instructions to enable Proxy Protocol for ELB based on these instructions.
But still no luck. The RemoteIPAddress
still returns the same ELB IP instead of the client IP.
Has anyone been able to get client IP when running an ASP.NET Core MVC app on AWS behind ELB? If so, how?
Any help would be greatly appreciated.
HttpContext.Request.Headers["X-Forwarded-For"].ToString()
– Dispread