我在我们的 Intranet 上有一个 Web 应用程序 (VS 2005)。有几个页面不需要用户登录到应用程序(反馈和默认页面)。我正在尝试获取域和用户名以显示和/或发送反馈。有没有办法在不需要用户登录的情况下执行此操作?我试过 this.Request.ServerVariables["LOGON_USER"]
和 this.User.Identity.Name
,但都没有用。
编辑:
我应该提到大多数用户的机器上都装有 Windows 2000。它适用于我的开发机器 (XP),但不适用于生产网络(我有 2000 个网络)。
最佳答案
Theresa,我想这就是你要找的......
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
WindowsIdentity identity = (WindowsIdentity)principal.Identity;
String userName= principal.Identity.Name;
关于c# - 在不登录的情况下获取 Intranet 上 Web 应用程序的域\用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/342088/