1

Is there a way to get the client's Public IP address in .Net Core Web API application?

I've tried Request.HttpContext.Connection.RemoteIpAddress but it gives the local IP and not Public IP.

and also I've tried getting IP from IPInfo, checkip.. and some more using webrequest but I am getting my server Public IP but not Client Public IP since the request is created from the server.

1 Answer 1

1

Sounds like there is some kind of proxy in between. It could also be a problem of the server Kesterl/IIS/nginx or whatever you might use.

Anyway what you are seraching for is the X-Forwarded-For header. You might have to configure your server/proxy and so on to add it or pass it through otherwise you will always get the internal IP.

In your app you have to check the value of this header to retrieve the real client IP.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.