如何验证对Active Directory的访问?

时间:2016-12-02 09:46:35

标签: c# .net active-directory

我正在进行某种健康监控,我想验证我的应用程序是否具有Active Directory中的访问权限。当我初始化DirectoryEntry时,这将显示我从机器看到给定的域/路径。没关系,但我需要检查一下我是否能够在域中读/写。它甚至可以在AD中创建实际对象吗?

谢谢你

1 个答案:

答案 0 :(得分:0)

最后,与老年人相比,这很容易。评论。这是我使用的代码:

                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
                    }
                }