Active Directory中的SetPassword非常慢 [英] SetPassword is very slow in Active directory

查看:79
本文介绍了Active Directory中的SetPassword非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我们能够在活动目录上成功创建新用户,但是SetPassword方法大约需要1.5分钟才能完成该过程.以下是SetPassword的代码段.有没有更好的方法来设置新用户的密码?

这是我们的生产环境类型.
•IIS 7
•ASP.NET 3.5(C#)
•Active Directory
•Windows Server 2008 R2


在此先感谢!!!

Hi All,
We are able to create new user successfully on the active directory but the SetPassword method is taking around 1.5 minutes to complete the process. Below is the code of the snippet of SetPassword. Is there any better approach to set the password of new user?

Here is our production environment type.
• IIS 7
• ASP.NET 3.5 (C#)
• Active Directory
• Windows Server 2008 R2


THANKS IN ADVANCE!!!

  #region SetPassword
  /// <summary>
  /// This function is used to set user password
  /// </summary>
  /// <param name="path"></param>
  /// <param name="userPassword"></param>
  /// <remarks>

/// </remarks>
  internal static void SetPassword(string path, string userPassword)
  {
      if (_logger.IsDebugEnabled)
          _logger.Debug("ADHelper.cs : Enter SetPassword");

      try
      {
          using (DirectoryEntry usr = GetDirectoryEntry(path))
          {
              object ret = usr.Invoke("SetPassword", userPassword);
              usr.CommitChanges();
              usr.Close();
          }

          if (_logger.IsDebugEnabled)
              _logger.Debug("ADHelper.cs : Exit SetPassword");
      }
      catch (Exception ex)
      {
          if (_logger.IsErrorEnabled)
              _logger.Error("ADHelper.cs : Exception occurred in SetPassword. Message: ", ex);

          throw ex;
      }
  }

  #endregion



添加用户代码段



Add user snippet

#region AddUser

    /// <summary>
    /// This function is used to add user to active directory
    /// </summary>
    /// <param name="adPath">Active Directory</param>
    /// <returns>directory entry object</returns>
    /// <remarks>
    /// </remarks>
    public static void AddUser(ADUser adUser)
    {
        if (_logger.IsDebugEnabled)
            _logger.Debug("ADHelper.cs : Enter AddUser");

        // Local variables
        DirectoryEntry oDE = null;
        DirectoryEntry oDENewUser = null;
        DirectoryEntries oDEs = null;

        try
        {
            oDE = GetDirectoryEntry(GetADPath(Constants.EnvironmentType.PROD, adUser.UserType));

            // 1. Create user account
            oDEs = oDE.Children;
            oDENewUser = oDEs.Add(string.Format("{0}=", Constants.ADAttributes.CN) + adUser.UserName, "user");

            // 2. Set properties
            SetProperty(oDENewUser, Constants.ADAttributes.givenName, adUser.FirstName);
            SetProperty(oDENewUser, Constants.ADAttributes.sn, adUser.LastName);
            SetProperty(oDENewUser, Constants.ADAttributes.mail, adUser.Email);
            SetProperty(oDENewUser, Constants.ADAttributes.sAMAccountName, adUser.UserName);
            oDENewUser.CommitChanges();

            // 3. Set password
            SetPassword(oDENewUser.Path, adUser.Password);

            // 4. Enable account
            EnableAccount(oDENewUser);

            oDENewUser.Close();
            oDE.Close();

            if (_logger.IsDebugEnabled)
                _logger.Debug("ADHelper.cs : Exit AddUser");
        }
        catch (Exception ex)
        {
            if (_logger.IsErrorEnabled)
                _logger.Error("ADHelper.cs : Exception occurred in AddUser. Message: ", ex);

            throw ex;
        }
        finally
        {
            if (oDENewUser != null)
            {
                oDENewUser.Dispose();
                oDENewUser = null;
            }

            if (oDEs != null)
            {
                oDEs = null;
            }

            if (oDE != null)
            {
                oDE.Dispose();
                oDE = null;
            }
        }
    }

    #endregion

推荐答案

这些CP文章可能会对您有所帮助:

http://www.codeproject.com/KB/system/everythingInAD.aspx [ ^ ]

http://www.codeproject.com/KB/system/active_directory_in_vbnet.aspx [ ^ ]
These CP articles might help you out :

http://www.codeproject.com/KB/system/everythingInAD.aspx[^]

http://www.codeproject.com/KB/system/active_directory_in_vbnet.aspx[^]


看起来像您应该将oDENewUser传递给SetPassword而不是path并使用它.

祝你好运!
Looks like you should pass oDENewUser to SetPassword instead of path and use that.

Good luck!


这篇关于Active Directory中的SetPassword非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆