0
我有一些代码检索用户所属的Active Directory组。在本地主机上它会返回正确的结果,但是当部署到另一台计算机(同一网络上的Web服务器)时,返回的结果会少得多。不同计算机上Active Directory“memberof”的不同结果
我正在指定AD服务器和一个特殊的用户名和密码,我被管理员授予访问权限。
DirectoryEntry de = new DirectoryEntry("LDAP://***:389", "***", "***");
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(samaccountname=" + search + "))";
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Add("*");
SearchResult rs = ds.FindOne();
if (rs != null)
{
if (rs.GetDirectoryEntry().Properties["memberof"].Value != null)
//rest of code removed
我也尝试了不同的方法和结果也不同......
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "***, "***", "***"))
{
UserPrincipal user = UserPrincipal.FindByIdentity(pc, name);
if (user != null)
{
List<string> groups = new List<string>();
PrincipalSearchResult<Principal> groups2 = user.GetAuthorizationGroups();
//rest of code removed
我本来认为通过指定用户名和密码,其结果应该是一样的。任何想法为什么发生这种情况?
我想你误会了。如果我在localhost和web服务器上运行这两个相同的代码,它们会根据服务器返回不同的结果。 – johna
他们是不同的安全上下文吗?看看https://support.microsoft.com/en-us/kb/331951。这是过时的,但基本上有读取这些数据的权限要求。 –
感谢您的回复。我正在使用同一个AD帐户在两台服务器上查询,还是计算机本身很重要? – johna