简体   繁体   English

如何获取登录用户名的客户端计算机

[英]How can i get the Logged in user Name of Client machine

How can i get the LoggedIn in user Name of Client machine 如何在客户端计算机的用户名中获取LoggedIn

without client providing the useid and password... (wjen the users visits the page i need to get In which user Id he/she loggedIn) 没有客户端提供useid和密码...(用户访问我需要获取的页面,他/她登录的用户ID)

I tried 我试过了

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

If you're in a domain environment you could enable Windows Authentication which will allow the users to bypass explicitly logging on in favor of NTLM authentication. 如果您在域环境中,则可以启用Windows身份验证,这将允许用户绕过显式登录以支持NTLM身份验证。 IE and Chrome work well with this out of the box, FF has a config setting for it. IE和Chrome可以很好地利用这个开箱即用,FF有一个配置设置。

EDIT 编辑

If you only care about browsers/OSs that support ActiveX then you can get it using Javascript with specific ActiveX privileges (from here ): 如果您只关心支持ActiveX的浏览器/操作系统,那么您可以使用具有特定ActiveX权限的Javascript(从此处 )获取它:

<script type="text/javascript"> 
<!-- 
var WinNetwork = new ActiveXObject("WScript.Network"); 
alert(WinNetwork.UserName); 
//--> 
</script>

It seems ServerVariables have been depreciated for C# in some instances. 在某些情况下,似乎已经为C#折旧了ServerVariables

If so, you'll need to do it this way: 如果是这样,你需要这样做:

string login = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

If you really want to use ServerVariables, keep in mind they are CaSe Sensitive in C#. 如果你真的想使用ServerVariables,请记住它们在C#中是CaSe敏感的 The correct casing is almost always UPPER , and here is the list of them: 正确的套管几乎总是UPPER ,这里是它们的列表:

List of ServerVariables ServerVariables列表

Try this Might be its work as per your requirement 试试这可能是你的工作根据你的要求

Request.ServerVariables["LOGON_USER"]

if Request.ServerVariables("LOGON_USER") Returns Empty String in ASP.NET Microsoft Guidline for that 如果Request.ServerVariables(“LOGON_USER”)返回ASP.NET Microsoft Guidline中的空字符串

You can use Request.LogonUserIdentity for getting client details. 您可以使用Request.LogonUserIdentity来获取客户端详细信息。

Response.Write(Request.LogonUserIdentity.Name); 回复于(Request.LogonUserIdentity.Name);

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

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