c# - change active directory password in sharepoint webpart -


i want change active directory password in web part in sharepoint when change password, stored account password in sharepoint not change , error:

this operation can performed on computer joined server farm users have permissions in sql server read configuration database. connect server server farm, use sharepoint products configuration wizard, located on start menu in microsoft sharepoint 2010 products.

this code change password:

 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();         }    } 

assuming ad server "in sharepoint farm", have run code account. solution impersonate admin user token has rights in ad server :

spuser adminuser = spcontext.current.web.siteusers[@"domain\username"]; using(spsite ositecollection = new spsite("http://yoursite", adminuser.usertoken)) {      //run code } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -