【问题标题】:get informaion about the user from its http request从其 http 请求中获取有关用户的信息
【发布时间】:2011-05-08 10:03:00
【问题描述】:

问:

我想问一下如何获取在我的网站上创建http request的用户的计算机名帐户名。根据他的要求.

当我搜索时,我发现:

  • REMOTE_HOST

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

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

  • 我使用REMOTE_USERLOGON_USERAUTH_USER获取账户名 但它也不包含任何数据

.

【问题讨论】:

    标签: c# .net asp.net httpwebrequest httprequest


    【解决方案1】:

    您可以像这样使用 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

    【讨论】:

    • 谢谢,但是,第一个给我127.0.0.1,第二个给我localhost,而我的计算机名称是:mm_h
    • 这是因为我在本地尝试了这些方法吗?
    • hmmm System.Net.Dns.GetHostName() 给出服务器的名称。 Request.ServerVariables["REMOTE_HOST"]给我ip地址。不是主机名,我想根据请求获取主机名和windows帐户。谢谢
    • @just_name:这很奇怪......给我一些时间......我正在寻找其他解决方案
    • @Just_name:对不起,我找不到任何解决方案....每个人都建议使用一些药物的代码(我已向你建议):(
    【解决方案2】:

    试试这个

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

    【讨论】:

    • 他们都得到了IP地址而不是hostname
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    相关资源
    最近更新 更多