繁体   English   中英

如何在asp.net中获取当前的Windows用户?

[英]How to get current windows user in asp.net?

我尝试了很多代码,它在我的本地服务器上成功运行。 但我尝试将远程服务器放到另一个字符串,如IIS APPPOOL,“servername”....我改为IIS管理器中的一些设置,但我失败了。 如何在远程服务器中获取用户名

我尝试了一些代码,如:

System.Security.Principal.WindowsPrincipal= System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

  string strName = p.Identity.Name;

要么

string strName = HttpContext.Current.User.Identity.Name.ToString();

要么

string Name = Environment.GetEnvironmentVariable("USERNAME");

要么

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

要么

WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
    string usernamex = currentIdentity.Name.ToString();

要么

HttpContext.Current.User.Identity.Name.ToString();

假设您使用的是IIS 7.5,请执行以下操作。 其他版本将类似。 所有上述获取用户名的方法都应该有效。

1) Double click on Authentication (This can be done at server level and your web site level so check both!)
2) Right click on Anonymous authentication and disable it and likewise enable Windows authentication
3) Click Basic settings. Check which application pool your website is using. Ensure it is using pass-through authentication for an "Application User" by clicking "Connect As" i.e. A user using a browser will be the person requesting authentication.
4) Click "Application Pools". Click the Application pool from (3). Click "Advanced Settings". Check the Identity is set to ApplicationPoolIdentity

双击身份验证

右键单击匿名身份验证并禁用它,同样启用Windows身份验证

检查您的网站使用的应用程序池检查应用程序池设置

HttpContext.Current.User应该没问题,但启用Windows身份验证的事实还不够:还要确保禁用匿名身份验证。

暂无
暂无

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

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