这段代码在AD服务器上执行时是正常的,但是在另外一台加入域的web服务器上执行时却报错。请各位高手给看看。
 //提升权限
WindowsImpersonationContext wic =  CreateIdentity("administrator", "nnt", "1111").Impersonate();
//帐号密码
string sAMAccountName = "TestUser5";
string newPassword = "2ws3ed$rf";DirectoryEntry de = new DirectoryEntry(ADPath,ADUser,ADPassword,AuthenticationTypes.Secure);DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + sAMAccountName + "))";deSearch.SearchScope = SearchScope.Subtree;try
{
SearchResult result = deSearch.FindOne();
de = new DirectoryEntry(result.Path);
de.Invoke("SetPassword", new object[]{newPassword});//-------此处抛异常!!!
de.CommitChanges();
de.Close();
//return de;
}
catch(Exception ex)
{
throw ex;
//return null;
}权限提升应该是没问题的。

解决方案 »

  1.   

    异常的errormessage是什么?调用的方法应该没错的。
      

  2.   

    erromsg:  System.Runtime.InteropServices.COMException: 出现了一个操作错误。现在我可以确定是权限的问题,因为在AD服务器上就可以正常执行,换到其他加入这个域的web服务器上就会报错。web服务器帐号已经加入到AD服务器中,而且设置了“信任委托”。
    web.config 里也设置windows集成验证:
    <identity impersonate = "true">
    <authentication mode="Windows" /> 会是在什么地方出错呢?