2016-12-02 115 views
1

我正在進行某種健康監測,我想驗證我的應用程序在Active Directory中具有訪問權限和適當的權限。當我初始化DirectoryEntry時,這會告訴我,我看到機器的域/路徑。沒關係,但我需要檢查是否可以在域中讀/寫。它甚至可能沒有在AD中創建實際對象?如何驗證對Active Directory的訪問?

感謝致敬

+0

看看在這個問題上的意見:http://stackoverflow.com/questions/4071260/how-to-get-effective-permissions-for-a-user-在-AD-LDS-入門的-C – oldovets

回答

0

最後,oldovets的評論很容易。下面是我使用的代碼:

   using (DirectoryEntry entry = directorySearcher.FindOne()?.GetDirectoryEntry()) 
       { 
        if (entry == null) 
        { 
         //report error 
        } 

        entry.RefreshCache(new string[] { "allowedAttributesEffective" }); 
        if (entry.Properties["allowedAttributesEffective"].Value != null) 
        { 
         if (this.properties == null || this.properties.All(property => entry.Properties["allowedAttributesEffective"].Contains(property))) 
         { 
          //sufficient rights 
         } 
         else 
         { 
          //insufficient rights 
         } 
        } 
        else 
        { 
         //not possible to check attribute "allowedAttributesEffective", it is missing or you have insufficient rights to read it 
        } 
       } 
相關問題