我使用以下代码通过 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 开发服务器,这就是为什么您会在调试中看到正确的用户。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)