在Sharepoint的WebPart中获取活动目录URL

本文关键字:活动 URL 获取 Sharepoint WebPart | 更新日期: 2023-09-27 18:18:21

是否有办法找出SharePoint webpart中当前活动目录的URL ?

如果我有URL,我可以使用这个构造函数创建访问AD与当前用户的凭据:

new DirectoryEntry(<URL>, null, null, AuthenticationTypes.Secure));

我可能会发现这个URL属性隐藏在这里的某个地方?

        SPSite sc = new SPSite(SPContext.Current.Site.ID);
        ServerContext context = ServerContext.GetContext(sc);
        UserProfileManager profileManager = new UserProfileManager(context);
        ...

或者是否有其他动态方式使用当前用户(具有AD读权限)创建连接到AD,而无需在配置文件中指定任何先前的参数?

在Sharepoint的WebPart中获取活动目录URL

您可以提取SPWebApplication上的人员选择器设置:

SPWebApplication.PeoplePickerSettings.SearchActiveDirectoryDomains

如果没有指定域,您可以使用全局编目作为回退:

GlobalCatalog gc = Forest.GetCurrentForest().FindGlobalCatalog();
DirectoryEntry entry = new DirectoryEntry("GC://" + gc.Name));