不向AD条目添加UserPrincipal字段

时间:2013-07-17 19:39:27

标签: c# userprincipal

我正在尝试向一个小应用程序添加一个没有UserPrincipal字段,但我无法让它工作。我尝试了几种方法来完成这个简单的任务,但我无法为我工作。我正在尝试添加一个名为Company的字段以插入Active Directory,但Company不是可以插入的字段...

有什么想法吗?如果您有代码示例,请发布代码示例。到目前为止我有这个:

public bool CreateNewUser(string sUserName, string sPassword, string sGivenName, string sSurname, string email, string phone)
    {
        if (!IsUserExisting(sUserName))
        {

            string sOU = "OU=Users,OU=External,DC=external,DC=rootteck,DC=com";

            PrincipalContext oPrincipalContext = GetPrincipalContext(sOU);

            UserPrincipal oUserPrincipal = new UserPrincipal(oPrincipalContext, sUserName, sPassword, true /*Enabled or not*/);

            //User Log on Name
            oUserPrincipal.Name = sUserName;
            oUserPrincipal.UserPrincipalName = sUserName + "@external.rootteck.com";
            oUserPrincipal.GivenName = sGivenName;
            oUserPrincipal.Surname = sSurname;
            oUserPrincipal.EmailAddress = email;
            oUserPrincipal.DisplayName = sGivenName + " " + sSurname;
            if (phone != string.Empty) { oUserPrincipal.VoiceTelephoneNumber = phone; }
            oUserPrincipal.PasswordNeverExpires = true;

            oUserPrincipal.Save();

            return true;
        }
        else
        {
            return false;
            //return GetUser(sUserName);
        }
    }

0 个答案:

没有答案