
如何在远程服务器中获取用户名
我尝试了一些代码,如:
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用户?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)