gpt4 book ai didi

c# - 从其 http 请求中获取有关用户的信息

转载 作者:太空狗 更新时间:2023-10-30 00:35:02 24 4
gpt4 key购买 nike

问:

我想问一下如何获取向我的网站发出http请求的用户的计算机名帐户名 site.according to his request.

当我搜索时,我发现:

  • REMOTE_HOST

    正在制作的主机名要求。如果服务器不有这个信息,它会设置REMOTE_ADDR 并将其留空。

    为什么服务器可能永远不会包含主机名?我该如何解决这个?

  • 我使用 REMOTE_USER , LOGON_USER ,AUTH_USER 获取账户名但它也不包含任何数据

.

最佳答案

您可以像这样使用 Request.ServerVariables 对象

// will return the host name making the request

string s = Request.ServerVariables["REMOTE_HOST"]


// will return the computer name
string s = Request.ServerVariables["SERVER_NAME"]

编辑

如果你想获取计算机名称,请尝试以下操作

string computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;

Response.Write(computer_name);

编辑二

//检索客户端机器详细信息

System.Net.IPAddress[] strClientIPAddress = System.Net.Dns.GetHostAddresses(Environment.MachineName);
string strClientMachineName = Environment.MachineName.ToString().Trim();
string strClientUserName = Environment.UserName.ToString().Trim();
string strClientDomainName = Environment.UserDomainName.ToString().Trim();
string strClientOSVersion = Environment.OSVersion.ToString().Trim();

有关更多服务器变量,请查看以下链接

IIS Server Variables

关于c# - 从其 http 请求中获取有关用户的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com