c# - WCF 服务中的 System.DirectoryServices.AccountManagement.PrincipalContext 和模拟

标签 c# active-directory directoryservices

在 WCF 服务背后的代码中使用 PrincipalContext。 WCF 服务正在模拟,以允许“传递”类型的身份验证。

虽然我对 Active Directory 所做的其他所有事情(主要是 System.DirectoryServices.Protocols 命名空间)在这种情况下都可以正常工作,但出于某种原因,System.DirectoryServices.AccountManagement 中的类会出现问题。失败的示例代码:

PrincipalContext context = new PrincipalContext(ContextType.Domain, domainName);
UserPrincipal user = 
    UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, UserName);

当我调用 FindByIdentity 时,我收到 COMException:“发生操作错误”。调用 PrincipalContext 也会失败,例如:

string server = context.ConnectedServer;

OperationContext.Current.ServiceSecurityContextThread.CurrentPrincipal.Identity 都表明模拟工作正常。而且,正如我所说,S.DS.P 中的其他 AD 任务运行良好。

如果我在 PrincipalContext 上明确设置凭据,一切正常。例如:

PrincipalContext context = 
    new PrincipalContext(ContextType.Domain, domainName, user, password);
UserPrincipal user = 
    UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, UserName);

现在一切正常。但是我不会知道来电者的用户名和密码;我必须依靠模仿。

关于什么会导致我所看到的问题的任何想法?

提前致谢! 詹姆斯

最佳答案

确保为应用程序池设置了 spn,在 AD 中设置了委派,并且应用程序池帐户具有操作系统权限的一部分。

关于c# - WCF 服务中的 System.DirectoryServices.AccountManagement.PrincipalContext 和模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3507476/

相关文章:

c# - 这个 ReSharper 片段 'convert to method group' 实际上在做什么?

c# - Redis Sentinel C# 客户端

.net - UserPrincipal 对象中的域名在哪里?

c# - 如果c# wpf中的可见性为 'Auto',如何知道 ListView 的VerticalScrollbar是否可见?

c# - 迭代枚举类型

powershell - 使用 CSV 作为输入清理 AD

c# - 访问 Active Directory 所需的权限?

php - LDAP 更改密码 PHP

c# - Active Directory 列表 OU

c# - 提高 System.DirectoryServices.AccountManagement 的性能