Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从用户的http请求获取有关用户的信息_C#_.net_Asp.net_Httpwebrequest_Httprequest - Fatal编程技术网

C# 从用户的http请求获取有关用户的信息

C# 从用户的http请求获取有关用户的信息,c#,.net,asp.net,httpwebrequest,httprequest,C#,.net,Asp.net,Httpwebrequest,Httprequest,问: 我想询问如何根据用户的请求,获取向我的网站发出http请求的计算机名和帐户名 当我搜索时,我发现: 远程主机 正在创建的主机的名称 请求。如果服务器没有 如果有此信息,它将设置为 远程添加,并将其留空 为什么服务器可能永远不包含主机名?我该怎么修理 这个 我使用远程用户,登录用户, AUTH_USER获取帐户名 但它也不包含任何数据 .试试这个 System.Web.HttpContext.Current.Request.UserHostName; System.Web.HttpCon

问:

我想询问如何根据用户的请求,获取向我的网站发出
http请求的计算机名帐户名

当我搜索时,我发现:

  • 远程主机

    正在创建的主机的名称 请求。如果服务器没有 如果有此信息,它将设置为 远程添加,并将其留空

    为什么服务器可能永远不包含主机名?我该怎么修理 这个

  • 我使用
    远程用户
    登录用户
    AUTH_USER
    获取帐户名 但它也不包含任何数据
.

试试这个

System.Web.HttpContext.Current.Request.UserHostName;
System.Web.HttpContext.Current.Request.UserHostAddress;

您可以使用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);
编辑II

//检索客户端计算机详细信息

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();
有关更多服务器变量,请查看以下链接


谢谢,但是,第一个给了我
127.0.0.1
,第二个给了我
localhost
,而我的计算机名是:
mm\u h
。这是因为我在本地还是不在本地尝试这些方法?hmmm
System.Net.Dns.GetHostName()
给出服务器的名称<代码>请求。ServerVariables[“REMOTE_HOST”]
给我ip地址。不是主机名,我想根据请求获取主机名和windows帐户。thanks@just_name字体真奇怪……给我点时间……我在找别的solution@Just_name:对不起,我找不到任何解决方案…每个人都在建议代码(我已经建议你)服用一些药物:(他们两人都获得ip地址,而不是
主机名。