string userName=System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
在本地PC上进行调试时,获得Windows用户名,但是在服务器上运行时,获得“ NT AUTHORITY \ NETWORK SERVICE”;
答案 0 :(得分:0)
您应该尝试在配置中将身份验证模式设置为Windows,并在授权标签中禁用匿名用户。 (from a previous answer):
要使当前登录的用户进入Windows帐户,您必须使用Windows authentication
而不是Forms authentication
:
在本地PC上进行调试时,获得Windows用户名,而在服务器上获得“ NT AUTHORITY \ NETWORK SERVICE”;
显示应用程序当前用户。当您将应用程序托管在Visual Studio Web服务器上时,它将使用您的本地帐户。但是,当您使用不同的凭据登录Web应用程序时,它将始终显示您当前的Windows登录信息。
在您的情况下,部署到IIS的应用程序使用NT AUTHORITY \ SYSTEM帐户。