Get the client's IP address
You can use IHttpContextAccessor
:
private IHttpContextAccessor _accessor;
public Foo(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
Now you get IP address this way"
var ip = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
HttpContext.Connection.RemoteIpAddress
is the property you are looking for