c# – 如何在asp.net中获取当前的Windows用户?
发布时间:2020-12-15 23:24:09 所属栏目:百科 来源:网络整理
导读:我尝试了很多代码,它在我的本地服务器上成功运行.但我尝试将远程服务器放到另一个字符串,如IIS APPPOOL,“servername”….我改为IIS管理器中的一些设置,但我失败了. 如何在远程服务器中获取用户名 我尝试了一些代码,如: System.Security.Principal.WindowsP
我尝试了很多代码,它在我的本地服务器上成功运行.但我尝试将远程服务器放到另一个字符串,如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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |