Couldn't find the UserHostName property on HttpRequest. And nothing about it in any forums. Has this been dropped? Any idea?
3 Answers
The accepted answer is not correct. someHttpContext.Request.Host corresponds to the Host header used in the HTTP request. For example: fetching http://example.org/test will result in example.org.
UserHostName used to return the DNS hostname of the client IP address making the request (which is someHttpContext.Connection.RemoteIpAddress). It looks as though the only recourse is to manually resolve the DNS hostname from the IP address with e.g. Dns.GetHostEntry.
11 Comments
UserHostName equivalent.UserHostName? Because it seems you are just trying to guess that it is possible, while you are not sure 100%.In "old" ASP.NET this was relying on IIS, that puts user hostname into "REMOTE_HOST" server variable.
Since ASP.NET Core is cross platform, it does not have this feature.
But if you run on Windows, and on IIS, you can still access it via HttpContext
var svf = httpContext.Features.Get<IServerVariablesFeature>();
if (svf == null)
{
//we're on linux, sorry, no luck
}
else
{
var hosteName = svf["REMOTE_HOST"];
}