gpt4 book ai didi

c# - WindowsIdentity.GetCurrent().Name 获取应用程序池名称而不是用户名

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:12 26 4
gpt4 key购买 nike

在我的开发机器上,这行代码正确地返回了我的用户名。

public class Constants
{
public static readonly string Username = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
}

但是当我将应用程序部署到测试网络服务器时,我得到了应用程序池的名称。

我正在使用 Windows 身份验证。

我无法弄清楚为什么会发生这种情况以及如何解决它。

最佳答案

确保在 IIS 中启用 Windows 身份验证并禁用匿名身份验证。

 <system.web>
<authentication mode="Windows"/>
<identity impersonate="true"/>
</system.web>

确保您的应用程序池通过单击“连接为”为“应用程序用户”使用直通身份验证。

确保您的网站在其下运行的应用程序池的身份设置为 ApplicationPoolIdentity。

或者,您可以使用 System.Web.HttpContext.Current.User.Identity.Name; 获取用户名。

关于c# - WindowsIdentity.GetCurrent().Name 获取应用程序池名称而不是用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45086106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com