无法在HttpRequest中找到UserHostName属性。在任何论坛中都没有相关信息。这个属性被删除了吗?有什么想法吗?
无法在HttpRequest中找到UserHostName属性。在任何论坛中都没有相关信息。这个属性被删除了吗?有什么想法吗?
someHttpContext.Request.Host
对应于HTTP请求中使用的Host
标头。例如:获取http://example.org/test将导致example.org
。
UserHostName
以前返回发出请求的客户端IP地址的DNS主机名(即someHttpContext.Connection.RemoteIpAddress
)。现在看来唯一的方法是使用例如Dns.GetHostEntry
手动解析IP地址的DNS主机名。var svf = httpContext.Features.Get<IServerVariablesFeature>();
if (svf == null)
{
//we're on linux, sorry, no luck
}
else
{
var hosteName = svf["REMOTE_HOST"];
}
试试这个
this.Request.Host.Value
RemoteIpAddress
执行DNS解析,例如使用Dns.GetHostEntry
等方法。 - Jesper