Xuan Lam
Xuan Lam

Reputation: 1

How to get IP Address in request?

I'm trying to get IP Address on Asp.net core API.

My system looks like this:

request(10.10.10.108) --> firewall (10.10.10.1) --> application

I used this code but it return 10.10.10.1, which is the IP of the firewall:

var ip = HttpContext.Connection.RemoteIpAddess;

How can I get the IP of request the client (10.10.10.108) in my application?

Upvotes: 0

Views: 117

Answers (1)

JustAnotherDev
JustAnotherDev

Reputation: 672

Check for the request header "X-Forwarded-For"

HttpContext.Current.Request.Headers["X-Forwarded-For"]

If this is populated it will likely contain the real origin of the request.

Upvotes: 3

Related Questions