如何设置.NET Windows身份验证 - 当我希望它使用实际用户时,该名称始终显示为"IIS APPPOOL\Classic .NET AppPool"

Eri*_*ric 5 .net c# kerberos windows-identity

我正在使用以下代码通过Kerberos进行身份验证.

IntPtr logonToken = WindowsIdentity.GetCurrent().Token;
string authenticationType = "WindowsAuthentication";
WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken, authenticationType);

//windowsIdentity.Name == equals "IIS APPPOOL\Classic .NET AppPool" when I want it to be the user
Run Code Online (Sandbox Code Playgroud)

这只有在我尝试运行我的.NET应用程序Web服务器时才会发生.如果我在我的机器上本地运行代码进行调试,它会在Name属性中显示我的用户ID.有关如何在Web服务器上运行的任何建议?

Zru*_*uty 1

您的问题是,您的 IIS 服务器以其自己的身份运行,而不是您的。因此,WindowsIdentity.GetCurrent().Token返回 IIS 工作进程的标识。

您可以使用 IIS 管理器控制台将您的网站配置为以不同身份(包括您的身份)运行: 在此输入图像描述