0
我創造用戶通過上添加Active Directory上的活動目錄管理器屬性PrincipalContext。我想添加一些額外的屬性,如Location,Initials,EmployeeId和Manager。如何通過使用PrincipalContext ASP.net,C#
我可以通過使用UserPrincipalEx類成功添加Location,Initials和EmployeeId。但我無法爲管理員屬性指定值。
當我試圖在分配manager屬性一些值,它會顯示一條錯誤消息出現一個約束衝突。「
這裏我的代碼是:
PrincipalContext ouContext = new PrincipalContext(ContextType.Domain, AD.ServerDomain, container, AD.LDAPUser, AD.LDAPPasswoprd);
UserPrincipalEx user = new UserPrincipalEx(ouContext);
user.GivenName = txtGivenName.Text;
user.Surname = txtSurName.Text;
user.DisplayName = Convert.ToString(txtDisplayName.Text);
user.Manager = txtSupervisor.Text; // What should I assign in this field
user.SetPassword("welcome1*");
user.Enabled = true;
user.ExpirePasswordNow();
user.Save(); // Here I am getting the error
我的擴展類:
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class UserPrincipalEx : UserPrincipal
{
public UserPrincipalEx(PrincipalContext context) : base(context) { }
public UserPrincipalEx(PrincipalContext context, string samAccountName, string password, bool enabled) : base(context, samAccountName, password, enabled) { }
public static new UserPrincipalEx FindByIdentity(PrincipalContext context,
string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context,
typeof(UserPrincipalEx),
identityValue);
}
public static new UserPrincipalEx FindByIdentity(PrincipalContext context,
IdentityType identityType,
string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context,
typeof(UserPrincipalEx),
identityType,
identityValue);
}
[DirectoryProperty("distinguishedName")]
public string DistinguishedName
{
get
{
if (ExtensionGet("distinguishedName").Length != 1)
return null;
return (string)ExtensionGet("distinguishedName")[0];
}
set
{
ExtensionSet("distinguishedName", value);
}
}
[DirectoryProperty("manager")]
public string Manager
{
get
{
if (ExtensionGet("manager").Length != 1)
return null;
return (string)ExtensionGet("manager")[0];
}
set
{
ExtensionSet("manager", value);
}
}
請幫我解決這個問題,如何在管理領域賦值
你在哪裏得到UserPrincipalEx?我找不到那個。 –