简体   繁体   English

如何从Web api2中的请求获取远程用户名

[英]how can i get remote user name from request in web api2

I have a requirement to identify remote user name and his domain in my webApi 2.0 but unable to do so. 我需要在我的webApi 2.0中标识远程用户名及其域,但无法这样做。 I have tried to use few things 我试图用一些东西

ViewBag.userName1 = WindowsIdentity.GetCurrent().Name; ViewBag.userName1 = WindowsIdentity.GetCurrent()。Name;

ViewBag.userName2 = System.Web.HttpContext.Current.User.Identity.Name.ToLower();

 // will return the host name making the request
 ViewBag.remoteHost = Request.ServerVariables["REMOTE_HOST"];

// will return the computer name
 ViewBag.logonUser = Request.ServerVariables["LOGON_USER"]; 
 ViewBag.remoteUser = Request.ServerVariables["REMOTE_USER"];

 // will return the computer name
 ViewBag.serverName = Request.ServerVariables["SERVER_NAME"];

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

and output is 和输出是

NT AUTHORITY\IUSR 
null
10.91.145.111 
null
null
10.91.145.88 
53323-TZD-SITA 
IUSR 
NT AUTHORITY 
Microsoft Windows NT 6.3.9600.0

can anyone please help me to get remote username and domain name? 谁能帮我获得远程用户名和域名?

在IIS中启用窗口身份验证后,我已经解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM