【问题标题】:change active directory password in sharepoint webpart在 sharepoint webpart 中更改活动目录密码
【发布时间】:2015-10-10 07:22:08
【问题描述】:

我想在 SharePoint 中更改我的 Web 部件中的活动目录密码,但是当我更改密码时,SharePoint 中存储的帐户密码没有更改,我收到此错误:

此操作只能由在 SQL Server 中具有读取配置数据库权限的用户加入到服务器场的计算机上执行。要将此服务器连接到服务器场,请使用 SharePoint 产品配置向导,它位于 Microsoft SharePoint 2010 产品的“开始”菜单上。

这是我更改密码的代码:

 public void ChangePassword(string usrDomain, string username, string oldPassword, string newPassword)
   {
       using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, usrDomain, username, oldPassword))
       {
           UserPrincipal user = new UserPrincipal(ctx);
           user = UserPrincipal.FindByIdentity(ctx, username);
           user.ChangePassword(oldPassword, newPassword);
           user.Save();

       }
   }

【问题讨论】:

    标签: c# asp.net windows sharepoint active-directory


    【解决方案1】:

    假设您的 AD 服务器“在共享点场中”,您将不得不使用另一个帐户运行您的代码。 解决方案是使用在 AD 服务器中具有权限的管理员用户令牌来模拟:

    SPUser AdminUser = SPContext.Current.Web.SiteUsers[@"domain\username"];
    using(SPSite oSiteCollection = new SPSite("http://YOURSITE", AdminUser.UserToken))
    {
         //run your code
    }
    

    【讨论】:

    • 在这行代码中 SPUser AdminUser = SPContext.Current.Web.SiteUsers[usrDomain + "\\" + username];我收到此错误:Microsoft.SharePoint.dll 中出现“Microsoft.SharePoint.SPException”类型的异常,但未在用户代码中处理
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多