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.