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

标签 c# .net asp.net httpwebrequest httprequest

问:

我想问一下如何获取向我的网站发出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/

相关文章:

asp.net - 如何拦截对 WCF .svc 服务中方法的所有调用?

c# - WinRt : twoway binding for Appbar does not work

c# - 声明 C# 属性

c# - 将颜色传递给IValueConverter

.net - DataGridView 绑定(bind)到DataTable。获取枚举的组合框

c# - 使用 SAS 将文件从 Azure Blob 存储下载到浏览器

c# - 编写 SQL 查询以从 CRM 2011 读取数据

.net - 更改 NHibernate Session.Save 命令超时

c# - 如何更改 RSACryptoServiceProvider 的 CSP 参数

c# - 以编程方式在 IIS6 中启用 ASP.NET