当我将ASP.NET CORE WEB项目部署到Linux服务器时,即使其他人使用相同的URL连接到Linux服务器,它也始终显示我的LAN ID,它仍然在其网站上显示我的Lan ID。
这是我尝试过的:
string mylanid = "";
if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux)))
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "sh";
psi.Arguments = "-c whoami";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
Process proc = new Process
{
StartInfo = psi
};
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
mylanid = output;
}
else
{
mylanid = Environment.UserName;
}
首先,它检查OSPlatform
是否为Linux
,它处于第一种情况,并使用string output = proc.StandardOutput.ReadToEnd();
返回LAN ID。
对于Windows
,我使用mylanid = Environment.UserName;
,它可以正常工作。
它应该为Linux
做些什么,代码应该绕过服务器并从浏览器本身获取LAN ID
。这就是我想要的。
谢谢