要获取系统中的当前登录用户,我使用以下代码:
string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
我在 ASP.NET 应用程序上工作,我需要这些信息。所以我把我的应用程序放在服务器上并尝试了上面的代码,我在字符串 opl 中得到了“Network Service”。我需要知道访问我的 ASP.NET 应用程序的 PC 的当前用户。
最佳答案
快速的答案是 User = System.Web.HttpContext.Current.User
确保您的 web.config 具有以下身份验证元素。
<configuration>
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
延伸阅读:Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application
关于c# - 如何获取正在访问 ASP.NET 应用程序的当前用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5417125/