繁体   English   中英

如何设置 .NET WindowsAuthentication - 当我希望它使用实际用户时,名称始终显示为“IIS APPPOOL\\Classic .NET AppPool”

[英]How do I set up .NET WindowsAuthentication - the name always shows up as “IIS APPPOOL\Classic .NET AppPool” when I want it to use the actual user

我正在使用以下代码通过 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

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

您需要在 web.config 中启用模拟

要将 ASP.NET 配置为将 IIS 提供的 Windows 标识模拟为 ASP.NET 应用程序的 WindowsIdentity,请编辑该应用程序的 Web.config 文件并将标识配置元素的 impersonate 属性设置为 true,如下所示例子。

 <configuration> <system.web> <identity impersonate="true" /> </system.web> </configuration>

当您在本地运行代码进行调试时,您可能正在使用以登录用户身份运行的 Web 开发服务器,这就是为什么您会在调试中看到正确用户的原因。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM