1

I have a microservice application consisting of three microservices:

Gateway using Ocelot Identity microservice Core API microservice However, when I try to retrieve the client's IP address from the Core API, while passing through the gateway, I receive "(::1)" instead of the actual IP address.

  public class IdentityService : IIdentityService
{
    private IHttpContextAccessor _context; 

    public IdentityService(IHttpContextAccessor context)
    {
        _context = context ?? throw new ArgumentNullException(nameof(context));
    }
  
    public string GetCleintAdressIP()
    {
        string clientIpAddress = $"({_context?.HttpContext.Connection.RemoteIpAddress.ToString() ?? "unknown"})";
        return clientIpAddress;
    }
}

How can I correctly obtain the client's IP address in this setup?

Please note any relevant code/configuration snippets and error messages to help diagnose the issue.

0

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.