Hi All,
I have a webpage project that can create user in Active directory.
It works fine with active directory 2003. But on Active Directory 2008 I can not create account through my webpage. It alsway show "access denied". Here is my code:
using (Aladin.Security.RevertToAppPool.Revert())
{
using (Aladin.Security.ScopeImpersonator imp = new Aladin.Security.ScopeImpersonator(this.administrativeLoginName, this.domainName, administrativePassword))
{
using (DirectoryEntry user = ouEntry.Children.Add("CN=" + this.displayName, "user"))
{
this.SetDirectoryEntryProperty(user, "mail", email);
this.SetDirectoryEntryProperty(user, "UserPrincipalName", this.userName);
this.SetDirectoryEntryProperty(user, "sAMAccountName", this.userName);
this.SetDirectoryEntryProperty(user, "userAccountControl", ((int)UserStatus.Enable).ToString());
user.CommitChanges();
}
}
}
private void SetDirectoryEntryProperty(DirectoryEntry entry, string attribute, string value)
{
if (entry.Properties.Contains(attribute))
{
entry.Properties[attribute][0] = value;
}
else
{
entry.Properties[attribute].Add(value);
}
}
These above code run well if I use Administrator account. But it show message acess denied if I use other account which have the same permission with Administrator.
Can you have me to solve this issue.
Thanks,
Aladin