c#获取客户端用户名

问题描述:

我试图让我的客户端的登录用户名,但我仍然得到服务器信息。这是我改掉:c#获取客户端用户名

Environment.UserName; 
System.Security.Principal.WindowsIdentity.GetCurrent().User; 
System.Security.Principal.WindowsIdentity.GetCurrent().Name; 
System.Net.Dns.GetHostName(); 
Request.ServerVariables["REMOTE_ADDR"]; 
Request.UserHostAddress; 
+5

你还没有说过,但你的一些尝试建议这是ASP.Net。如果是这种情况,除非打开Windows身份验证,否则不会获取信息 – 2013-03-21 13:28:51

+0

是的,它适用于ASP.Net 4.5 – Butters 2013-03-21 13:30:00

+0

在服务器上部署应用程序,然后尝试在以Windows身份验证模式部署应用程序之后,您将获得此信息。 – 2013-03-21 13:36:30

通常我使用User.Identity.Name,它返回的登录名访问应用程序的用户输入。

例如var loginName = User.Identity.Name;