【问题标题】:Finding user's groups SIDs inside Sharepoint在 Sharepoint 中查找用户组 SID
【发布时间】:2011-12-16 09:58:25
【问题描述】:

我需要在我的 Sharepoint (2007) webpart 中找出当前用户所属的所有 AD 组 SID。

我想使用 System.DirectoryServices.AccountManagement 命名空间:

using (var context = new PrincipalContext( ContextType.Domain ))
{
    using (var user = UserPrincipal.FindByIdentity( context, accountName ))
    {
        var groups = user.GetAuthorizationGroups();
        ...
    }
}

,但我收到以下错误:

事件 ID:10016 通过权限设置(特定于应用程序)是地址 localhost 的用户 NT AUTHORITY \ NETWORK SERVICE(使用 LRPC)的 SID(S-1-5-20)未被授权为具有 CLSID 的 COM 服务器应用程序激活(本地) {61738644-F196-11D0-9953-00C04FD919C1}

这个http://support.microsoft.com/kb/899965 可以解决这个问题 但是这种方法需要更改注册表值(应用程序的所有权,因此您可以在 dcomcnfg 更改应用程序的值)以及稍后在 dcomcnfg 的 COM 安全性中更改用户权限,这对我来说不是一个选项。

还有其他方法可以访问 Sharepoint 中当前用户的组 SID?

我真的希望我能在 SPContext.Current.Web.CurrentUser.Groups 中找到这些值,但显然不是。

【问题讨论】:

    标签: c# sharepoint active-directory


    【解决方案1】:

    您需要在这里采用 SharePoint 方式,而不是使用 System 程序集,而是使用 SharePoint 程序集。

    每个用户的 SID 在SPUser.Sid 属性中。由于您只想查找 AD 组,您可以检查 SPUser.IsDomainGroup 属性。

    现在您需要做的就是检查当前用户:´SPContext.Current.Web.CurrentUser(aSPUser` 对象)。

    要回答您的问题如何获取用户所属的所有组,您实际上需要使用System.DirectoryServices。您的问题的解决方案显示在以下 stackoverflow 帖子中:

    简而言之:SPUser 对象以及通过 DirectoryServices 查询 Active Directory

    【讨论】:

    • 感谢重播。对我来说,该解决方案存在一个问题。在使用 System.DirectoryServices 时,我需要提供具有 AD 读取权限的用户的用户名和密码。有没有办法在不提供用户凭据的情况下通过 SharePoint 使用 System.DirectoryServices 访问 AD?例如,使用此构造函数并将用户名和密码字段留空并指定某种身份验证类型? public DirectoryEntry(string path, string username, string password, AuthenticationTypes authenticationType);
    • 指定具有读取权限的用户有什么问题?例如,您可以允许 Sharepoint 应用程序池的用户读取活动目录或为此创建专用用户。
    • 谢谢,除了向 DirectoryEntry 对象提供凭据外,我也没有其他选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多