public void SetPassword(string strUserDN, string strPassword)
    {
        string strDomainName = Utility.GetDomainName(strUserDN);        DirectoryEntry de = GetDirectoryEntryByDN(strDomainName, strUserDN);
        de.AuthenticationType = AuthenticationTypes.Secure;
        de.Invoke("SetPassword", new object[] { strPassword });        de.CommitChanges();        //密码永不过期
        de.Properties["userAccountControl"].Value = "66048";//66048是两个值的组合:密码永不过期(65536)+正常账号(512,未禁用)
        de.CommitChanges();    }“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG)) 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentException: 参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))源错误: 
行 61: 
行 62:         DirectoryEntry de = ADUser.GetDirectoryEntryByDN(strDomainName, strUserDN);
行 63:         de.Invoke("SetPassword", new object[] { strPassword });
行 64:         de.CommitChanges();
行 65: 
 源文件: f:\宜宾公安\WebSite\ADDemo.aspx.cs    行: 63 堆栈跟踪: 
[ArgumentException: 参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))][TargetInvocationException: 调用的目标发生了异常。]
   System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) +228
   ADDemo.SetPassword(String strUserDN, String strPassword) in f:\WebSite\ADDemo.aspx.cs:63
   ADDemo.SetPass(String strLoginID) in f:\WebSite\ADDemo.aspx.cs:39
   ADDemo.Button1_Click(Object sender, EventArgs e) in f:\WebSite\ADDemo.aspx.cs:25
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746  

解决方案 »

  1.   

    源文件: f:\宜宾公安\WebSite\ADDemo.aspx.cs 行: 63  这告诉你哪一行报错了吗,还有下面[ArgumentException: 参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))]表示这行参数有问题
      

  2.   

    de.Properties["userAccountControl"].Value = "66048"感觉这里有问题,改成int 类型试试
      

  3.   

    @  zhou_xuexide.Invoke("SetPassword", new object[] { strPassword });
    这行错误。这个是自带的DLL
      

  4.   

    const int ADS_UF_SMARTCARD_REQUIRED = 0x40000;
    val = (int) usr.Properties["userAccountControl"].Value;
    usr.Properties["userAccountControl"].Value = val | 
        ADS_UF_SMARTCARD_REQUIRED;
    usr.CommitChanges(); ---- 摘自msdn好像我说对了
      

  5.   

    @ whycomde.Properties["userAccountControl"].Value 是 OBJECT
      

  6.   

    object 是任何类型的基类
      

  7.   

    @ whycom
    没有到那一行 就出问题了。
    其他项目没有出问题。
    这个代码以前跑起来没有问题。
    不晓得是不是 AD服务器出问题了。
      

  8.   

    de.Invoke("SetPassword", new object[] { strPassword });反射?
      

  9.   

    你是在asp.net下用,果然如此,asp.net默认用户没有权限改ad
    你需要用 administrator 用户启动 asp.net 或者 打开 DirectoryEntry 时 加上管理员 用户名和密码
      

  10.   

    @whycom
    恩。
    添加了权限的
    Domain Admins