UserHostAddress in Asp.net Core

What is the equivalent in Asp.Net Core of the old HttpContext.Request.UserHostAddress?

I tried this.ActionContext.HttpContext but cannot find the UserHostAddress nor the ServerVariables properties.

Thanks


If you have access to the HttpContext, you can get the Local/Remote IpAddress from the Connection property like so:

var remote = this.HttpContext.Connection.RemoteIpAddress;
var local = this.HttpContext.Connection.LocalIpAddress;

This has moved since the original answer was posted. Access it now via

httpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress