0

我正在开发一个 SharePoint 应用程序,它需要来自指定 Windows Server 2003 Active Directory 组织单位的用户。

首先,我不关心 DirectoryServices 对象上的“Dispose”和“Close”操作。在这一点上,检索操作快速而成功。

但这在 2ish 尝试后导致“服务器无法运行”错误。而这个错误会使整个应用程序运行得更糟,就像停止其他 AD 操作一样。

然后,我通过在每个 DirectoryEntry、DirectorySearcher 和 SearchResultCollection 对象上添加 using 语句来纠正此错误。

然后我达到了一个点,我不再收到“服务器无法运行”错误。但是,当我尝试使用 DirectorySearcher.FindAll 方法从 AD 检索用户 1 次或更多次时,第一个操作快速且成功,其他操作更慢但成功。它有点需要超时的持续时间。你能帮我解决一下这个减速的情况吗?

这是示例代码:

using (DirectoryEntry directoryEntry = new DirectoryEntry(connectionString, userName, password))
            {
                using (DirectorySearcher search = new DirectorySearcher(directoryEntry))
                {
                    search.SearchScope = SearchLevel.OneLevel;
                    search.ReferralChasing = ReferralChasingOption.All;
                    search.Filter = filter;
                    search.SizeLimit = 200;
                    //Limits the property count for search result
                    SetUserDirectorySearcherPropertiesToLoad(search);

                    using (SearchResultCollection result = search.FindAll())
                    {
                        foreach (SearchResult searchResult in result)
                        {
                            // Get user attributes
                        }}}}

提前致谢

4

1 回答 1

0

这里的一切似乎都很正常。我正在使用类似的东西,唯一值得一提的区别是我通常将“propertiesToLoad”参数传递给 DirectoryEntry 的构造函数,以及将过滤器传递给 DirectorySearcher 的构造函数。

另一个区别是您为 DirectoryEntry 使用“用户名”和“密码”——也许值得使用应用程序池标识?我通常会SPSecurity.RunWithElevatedPrivileges(method pointer)接听这些电话。

于 2010-01-06T13:45:04.227 回答