它在本地工作,但是当我将我的网站上传到IIS服务器时它就不能工作了:这是我配置文件的一部分,我认为它可以工作:
<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
我的asp.net代码在本地运行但不在服务器上运行:
string[] temp = Convert.ToString(System.Security.Principal.WindowsIdentity.GetCurrent().Name).Split('\\');
string userName = temp[1] + "@" + temp[0];
Console.WriteLine("name: "+ userName);
保存的名称/错误是
NT AUTHORITY\IUSR
我正在使用Windows Server 2012版本6.2 如何获取Windows用户名?
答案 0 :(得分:0)
答案 1 :(得分:0)
您可能使用了错误的财产。 您正在使用的将返回运行IIS的帐户的用户名。因此,如果您运行的是IIS Express,那么在您的计算机上它将是您的帐户,如果它位于已部署的IIS服务器上,它将成为运行AppPool的服务帐户。
要获取连接的实际用户/机器的帐户名称,请使用
string[] temx = Convert.ToString(HttpContext.Request.LogonUserIdentity.Name).Split('\\');
假设您已关闭匿名并正在使用某种身份验证。