.NET Core RunImpersontated()身份验证问题

时间:2018-09-20 05:45:13

标签: c# .net-core windows-authentication

我在一个项目上有一个.NET Core 2.1后端。我正在为Intranet应用程序使用Windows身份验证。我可以使用以下方法在控制器中获得经过身份验证的用户:

return Ok("User:" + User.Identity.Name);

我需要访问网络资源以读取文件列表。 MS的文档谈论的是Core不像旧框架那样使用模拟,而是提供RunImpersonated方法。

            WindowsIdentity.RunImpersonated(user.AccessToken, () =>
        {
            // user.Name gets the Windows user here

            foreach (string fileFound in Directory.EnumerateFiles(fileLocation)
            {
                fileList.Add(// Found File Data);
            }
        });

我在运行代码时收到未经授权的用户错误。我的Windows用户可以访问该位置。

IIS是使用Windows Auth设置的,但它是通过ApplicationPoolIdentity运行的。

任何帮助/想法将不胜感激!

0 个答案:

没有答案