2016-12-02 117 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 
        } 
       } 
相关问题