在 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.ServiceSecurityContext
和 Thread.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/