如何在asp.net core中获取客户端的计算机名

4 c# model-view-controller asp.net-core

我尝试过

System.Net.Dns.GetHostEntry(HttpContext.Connection.RemoteIpAddress.ToString()).ToString();
Run Code Online (Sandbox Code Playgroud)

但这没有用。我也尝试过使用

PCName = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName; 
Run Code Online (Sandbox Code Playgroud)

但这对于核心似乎已被弃用

小智 7

尝试这个。

using Microsoft.AspNetCore.Http;
using System.Net;

Dns.GetHostEntry(HttpContext.Connection.RemoteIpAddress).HostName;
Run Code Online (Sandbox Code Playgroud)