【问题标题】:How to get the web requesting domain user information in web application如何在 Web 应用程序中获取 Web 请求域用户信息
【发布时间】:2014-02-05 12:06:39
【问题描述】:

我正在使用 Windows 8 及其域。使用机器登录的凭据信息,我必须传递访问同一域中网站的信息。 (如客户端登录机器的用户名等信息。)

我尝试了以下代码:

string dsfsdf = Page.User.Identity.Name;

无法获取请求者信息。

【问题讨论】:

    标签: c# asp.net iis windows-authentication


    【解决方案1】:

    您可以通过执行以下操作从 WindowsIdentity 对象中获取用户信息

    WindowsIdentity identity = HttpContext.Current.Request.LogonUserIdentity;
    

    您可以找到有关对象here的信息

    有一个名为 Name 的属性将为您提供经过身份验证的用户名。

    要获取客户端机器名称,您可以使用:

    string clientMachineName = Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多