我用管理员设置密码的时候不会报错,用普通用户设置的就报错了:调用的目标发生了异常.
我不知道在哪设置权限。请高人指点下啊,谢谢了!public DirectoryEntry GetUser(string sAMAccountName)
        {
            DirectoryEntry temp = null;
            try
            {
                DirectoryEntry entry = new DirectoryEntry(ldapPath + ldapDomain, adminName, adminPassword,AuthenticationTypes.Secure);                DirectorySearcher mySearcher = new DirectorySearcher(entry);                mySearcher.Filter = ("(objectClass=user)");                foreach (SearchResult resEnt in mySearcher.FindAll())
                {
                    DirectoryEntry de = resEnt.GetDirectoryEntry();
                    string name = de.Properties[ADUserProperties.sAMAccountName].Value.ToString().ToLower();
                    if (name == sAMAccountName.ToLower())
                    {
                        temp = resEnt.GetDirectoryEntry();
                        break;
                    }
                }
            }
            catch
            { }
            return temp;
        } public bool SetPassword(ADUserInfos adUser)
        {
            bool isSuccess = false;
            try
            {
                DirectoryEntry user = GetUser(adUser.SAMAccountName);                // 模拟超级管理员,以达到有权限修改用户密码,这个模拟加和没加一个样。
                NtsIdentityImpersonation impersonate = new NtsIdentityImpersonation(AdminName, AdminPassword, LdapDomainName);
                impersonate.BeginImpersonate();                user.Invoke("SetPassword", new object[] { adUser.PassWord });                impersonate.StopImpersonate();                user.Close();
                //user.Invoke("SetPassword", adUser.PassWord);
                //user.CommitChanges();
                isSuccess = true;
            }
            catch
            { }
            return isSuccess;
        }

解决方案 »

  1.   

    user.Invoke("SetPassword", new object[] { adUser.PassWord }); 问题出在这行。
    同志们顶顶啊
      

  2.   

    SetPassword  是密码吧  
     new object[]   是为什么呢 
      

  3.   

    数据类型   SetPassword    应当是  string吧   
    为什么  new object[]  呢 
    查看具体的    错误   继续 断点 
      

  4.   

    AD倒是研究过多次,但一般很少去使用代码去更改密码的,毕竟更改AD账户的密码一般都是使用AD本身的工具来处理。给你一个链接,你分析一下看看里面是怎么实现的。http://www.codeproject.com/KB/IP/StorerActiveDirectory.aspx
      

  5.   


    在web.config里面的<authentication mode="Windows" />底下加 
    <identity impersonate="true" userName="YourAdminUsr" password="YourAdminPwd"/>