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