【问题标题】:Retrieve and Edit Sharepoint Active Directory User Profile Properties检索和编辑 Sharepoint Active Directory 用户配置文件属性
【发布时间】:2014-05-21 10:01:11
【问题描述】:

我的 Web 应用程序是一个使用 HTML5 和 Jquery 的 ASP.NET MVC 4 Web 应用程序。

我正在编写一个 Web 应用程序,以使用 Active Directory 从 Sharepoint 服务器检索和编辑数据。

我能够很好地检索信息,但我正试图找出一种方法来编辑和提交对活动目录帐户的更改。我无法在任何地方找到与远程 Web 应用程序访问相关的代码示例。我见过的唯一编辑示例只能在 SharePoint 服务器上完成。

我想知道我们是否完全遗漏了有关 Active Directory 的某些内容,以及我正在尝试做的事情是否可能。

注意:

到目前为止,我还没有找到用于编辑 Active Directory 信息的代码。这是我目前用于检索的代码。我希望能够提取信息,编辑名字或姓氏等属性,然后将更改提交到 SharePoint Active Directory。

提前感谢您的回答!

ClientContext currentContext = new ClientContext(serverAddress);
        currentContext.Credentials = new System.Net.NetworkCredential(adminAccount, password);

        const string targetUser = "domain\\targetAccountName";

        Microsoft.SharePoint.Client.UserProfiles.PeopleManager peopleManager = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(currentContext);
        Microsoft.SharePoint.Client.UserProfiles.PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);

        currentContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
        currentContext.ExecuteQuery();

        foreach (var property in personProperties.UserProfileProperties)
        {
            //Pull User Account Name
            //Edit Account name to new value
            //Commit changes
        }            

【问题讨论】:

    标签: c# asp.net-mvc-4 sharepoint web-applications active-directory


    【解决方案1】:

    看起来 PersonProperties 类仅提供只读访问权限,因为所有属性仅显示 Get。 MSDN PersonProperties

    如果您想留在 SharePoint 中,您似乎需要查看UserProfile class。该页面有一个很好的示例,即检索帐户然后设置一些属性。

    如果您不需要特定于 SharePoint 的属性并且想要一种易于使用的格式,您可以检索 UserPrincipal。它可以让您轻松访问常用的用户属性。

    using (var context = new PrincipalContext(ContextType.Domain, "domainServer", 
                                "DC=domain,DC=local", adminAccount, password))
    {
        var userPrincipal = UserPrincipal.FindByIdentity(context, 
                                IdentityType.SamAccountName, "targetAccountName");
        if (userPrincipal != null)
        {
            userPrincipal.GivenName = "NewFirstName";
            // etc, etc.
        }
    }
    

    【讨论】:

    • 谢谢!这正是我一直在寻找的。似乎有很多不同的方法可以获取这些 SharePoint 特定属性。
    猜你喜欢
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    相关资源
    最近更新 更多