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

c# – 如何在asp.net中获取当前的Windows用户?,第1张

概述我尝试了很多代码,它在我的本地服务器上成功运行.但我尝试将远程服务器放到另一个字符串,如IIS APPPOOL,“servername”….我改为IIS管理器中的一些设置,但我失败了. 如何在远程服务器中获取用户名 我尝试了一些代码,如: System.Security.Principal.WindowsPrincipal= System.Threading.Thread.CurrentPrinc 我尝试了很多代码,它在我的本地服务器上成功运行.但我尝试将远程服务器放到另一个字符串,如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 authentication3) 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
总结

以上是内存溢出为你收集整理的c# – 如何在asp.net中获取当前的Windows用户?全部内容,希望文章能够帮你解决c# – 如何在asp.net中获取当前的Windows用户?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1219588.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存